Skip to content

Tag: swing

Jtree not shown on adding a node!

I have a static jtree in a scrollpane. And now iam trying to add child to jtree, it got added successfully. Now, the added node is not visible in the jtree. Try 1: I have tried with model.reload() Try 2: I have tried with tree.setModel() too… Even then newly added child is not visible. but Its getting a…

How to open warning/information/error dialog in Swing?

How to open warning/information/error dialog in Swing? I need standard error dialog with “Ok” button and “red cross” image. I.e. analog of org.eclipse.jface.dialogs.MessageDialog.openError() Answer See How to Make Dialogs. You can use: And you can also change the symbol to an error mes…

How to make Java Swing components fill available space?

I cannot seem to get my Java Swing components to work together correctly. What I want to do, is have a JPanel fill ALL the space available inside a JTabbedPane. At the moment, my setup is as follows: This creates a windows that is my desired size (dynamically proportional to the screen size, not included in a…

What is the simplest way to draw in Java?

What is the simplest way to draw in Java? This doesn’t work and I have no idea how to get anything to appear. Answer Easiest way: You simply need to extend JPanel and override the paintComponent method of the panel. I’d like to reiterate that you should not be overriding the paint method. Here is …

bring JInternalFrame to the front

I have a JDesktopPane which contains a number of JInternalFrames. I’d like to be able to bring any JInternalFrame to the front, overlaying any other active frames. I found a number of code samples to do this, but none seem to work – the frame does NOT go on top of other active JInternalFrames. E.g…

Dynamically change JComboBox

I am fetching the data values from the database successfully. I have also stored them into a String[] array. I need to load the String array as the items of the JComboBox in response to key actionperformed. How can I reload the items of the JComboBox whenever a key is pressed as the fetched values depend on t…

TableModelListener and multiple column validation

This is the first time for me to post here, so sorry if I made some mistake. I am working on a JTable which column data have to verify some parameters, for example: Column 3 values > 30 Column 4 values > 10 Column 5 values > 4 Also the first 2 columns are filled “automatically”, putting 0…