swing

Switching values when editing a cell

I have a JTable which uses a custom TableModel to display a series of object instances. There's a switch case inside getValueAt(int row, int column) to return values according to given attributes (see below). One return statement involves returning a value of 1/0 as true/false. Is there a way that I can modify this TableModel so that it...

How to avoid blocking EDT with JPA lazy loading in Swing desktop apps

I'm struggling with real-world use of JPA (Hibernate, EclipseLink, etc) in a Swing desktop application. JPA seems like a great idea, but relies on lazy loading for efficiency. Lazy loading requires the entity manager exist for the lifetime of the entity beans, and offers no control over what thread is used for loading or any way to do t...

Workflow UI in Java

Does anyone know of a Java (Swing) based UI framework for building a Workflow application? -Users are given a set of activities -They can drag and drop these activities -Link activities to each other (workflow steps) ...

How can you disable all sorting code in JTable in 1.6

I have a JTable extension that has been in use since Java 1.3/1.4 in the project that provided things like column reordering and sorting by clicking on the column. We are upgrading to Java 1.6, and the new JTable stops the old sorting code from working. It would be somewhat extensive rework to fit everything to the new JTable API. Until ...

How To Access Controls On a JPanel...?

I'm a Java n0ob....so let me apologize in advance... I've got a jPanel that I've added a bunch of controls to, dynamically, at run-time. Later, in my code, I want to loop through all of those controls (they are jCheckBoxes) to see if they are checked or not. In .NET - I'd be looking at some like... For Each myControl as Control In my...

How can I measure/calculate the size a Document needs to render itself?

I have a javax.swing.text.Document and I want to calculate the size of the bounding box that document needs to render itself. Is that possible? It is almost trivial for plain text (height = line count * line height, width = max width over each line) But how can I do this with RTF, HTML or any other document? ...

Scala swing 2.8 how do I set the background color of a Slider ?

Hi, How can I set the background color of a Slider in Scala Swing 2.8 final. I copied the UIDemo object provided in the distribution for my tests and added background = java.awt.Color.RED but that does not take effect on my mac. object UIDemo extends SimpleSwingApplication { ... object slider extends Slider { min = 0 value = tab...

Java Swing - Multiple column headers in a JTable?

Hello Community. Is there any way to create multiple column headers in a JTable? I mean, normally there is only one row, but I need two of them with the same format (headerlike), and combine some cells of one of those headers. I need something like this: Header0 | Header123 | Header4 Header0 | Header1 | Header2 | He...

What are the best practices for internationalizing a Java Swing desktop application?

I'm sure there are a lot of methods, but what's the recommended way to do this that has the least amount of impact to your code? The obvious is that you create properties files, but how do you swap the values in the rendering? In J2EE you always just re-render the whole page so it's easy. But in Swing apps, do you just add the code for...

How can I customize the render of JRadioButton?

I've created a JRadioButton subclass in which I override the paintComponent method like so: @Override protected void paintComponent(Graphics g) { g.drawImage( isSelected() ? getCheckedImg() : getBasicImg() , 0, 0, this); } but it seems that once the button is drawn, that's the image it uses forev...

How to display a 2D array in jTable?

I have a static 2D array called "Status.Data[][]" and a Column header called "Status.Columns[]" I am using net beans and I want to be able to have the arrays populate the table. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { jTable1.setColumnModel(new DefaultColumnModel(Status.Data, Status.Columns));...

The gridBagLayout and the JscrollPanel

Cross Post: http://www.javaworld.com/community/node/4746 http://forums.sun.com/thread.jspa?messageID=11025554 1. GridBagLayout When I tried to use the GridBagLayout, I found that I can not change the weight of each component added in the container. For example,In the contentPanel of the JDialog, I added two sub panels: leftPanel and ...

How to read data only once in Java Swing?

I am new to Swing. I want to write a program which reads a file and draws something depending on the data read from the file. I checked the tutorials and they call the drawing methods in paint(). So I added the code to read the file too in the paint() method. However, I noticed that the paint() method may be called multiple times. So th...

Calculation of required display space for different subclasses of JComponent

Hello. For my current project i am writing a JTable based GUI. One of the main features is the ability to adjust the sizes of all cells at runtime, depending on the contents (which change over time). Currently all cells have the same height and width, when the application is started. I would like to change that to a more sophisticated a...

How to get rid of the border with a JTable / JScrollPane

Hi All, If you run the small sample below you'll see a border around the center region. I'm not sure why this border is showing. It happens when a JTable is in a JScrollPane. I tried various things to remove it but so far no luck. A JTable without the JScrollPane shows no border. See sample below. TIA. public class TestScrollPane e...

JTable - multiple cell editors in one column

I would like my JTable to use different cell editors for different cells in a single column. Think of a two-column label-value table like: Name | Value --------------+-------------------------------- Identifier | ST33442 (string editor) Purchase Date | 7/7/10 (custom calendar editor) Status | Broken (combo editor) H...

Java Dialog box to allow use to pick file

This is the code I have at present: import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.*; import java.io.File; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; imp...

How to avoid HeadlessException in thread?

I have tried to open a dialog box in Servlet & it opens fine. But then I tried to achieve same thing in my thread's run method. It gaved me following error: java.awt.HeadlessException at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159) at java.awt.Window.<init>(Window.java:431) at java.awt.Frame.<init>(Frame.java...

Java - Filling a Custom Shape

I have created a custom shape, essentially it is a collection of four Arc2D objects. When these arcs are drawn they form what could be considered a four point rounded star shape, kind of like a clover. Where one arc ends, the other begins. They form a square in the center. So imagine, taking a square and drawing half circles on every...

custom JComboBox top label

Hopefully an easy question. From the example on http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/uiswing/components/combobox.html on "Providing a Custom Renderer" section, I can make a JComboBox like Picture 3 - Text 3 ------------------- Picture 1 - Text 1 Picture 2 - Text 2 Picture 3 - Text 3 Picture 4 - Text 4 Picture 5 ...