Questions tagged [swing]

Swing is a user-interface toolkit in Java and is shipped with the standard Java SDK. It is contained within the package javax.swing.

Swing is a GUI toolkit that is packaged with the standard Java SDK (since 1.2). Recently it is no longer being actively enhanced and has largely been superseded by JavaFX.

General information

Specialized articles

Essential topics in Swing programming

Layout managers: Layout managers are responsible for determining the size and position of components in a Container.

Swing threading rules: Swing is single threaded and any access to Swing components should happen on the Swing thread (the Event Dispatch Thread or EDT).

  • Start with the Concurrency in Swing tutorial
  • Detect EDT violations using one of the approaches cited here
  • Use SwingWorker to perform lengthy operations in the background and update the UI on the EDT
  • Use a Swing Timer for animation
81029 questions
10
votes
2 answers

Was JFrame disposed?

I've got an application with several JFrame window. My main JFrame wants to know if another JFrame is already disposed. Which method shall I call to decide?
principal-ideal-domain
  • 3,998
  • 8
  • 36
  • 73
10
votes
5 answers

JTable with striped background

Using a different background color for odd and even rows is a commonly used trick to improve readability of large tables. I want to use this effect in Swing's JTable. I started out by creating a custom table renderer, but this can only be used to…
Kees Kist
  • 2,641
  • 5
  • 20
  • 25
10
votes
2 answers

Tooltip text for each column of a JTable header

I am trying to display the text in each cell of the header as a tooltip when you hover over that cell. I have found that you can set the tooltip for the entire header: table.getTableHeader().setToolTipText("asdf"); but cannot do similar for each…
Aequitas
  • 2,205
  • 1
  • 25
  • 51
10
votes
3 answers

Bad Swing UI scaling on high resolution (MS Surface)

I'm currently working on a little Java application, that involves Swing GUIs. On my development PC everything looks fine but when I run it on my MS Surface, some icons seem to be too large for the components (or the components too small for the…
Macklin
  • 167
  • 1
  • 11
10
votes
2 answers

"Un-rollover" a JButton when a JOptionPane is displayed

I have a situation where I need to display a JOptionPane after clicking on a JButton. The JButton has a default icon, and a rollover icon (which displays when, well, the mouse rolls-over the button). However, once the button is clicked and a…
aspiring_sarge
  • 2,355
  • 1
  • 25
  • 32
10
votes
8 answers

ALWAYS on top window

I'm searching for a solution in order to keep a JFrame always on top and with always I really mean always. setAlwaysOnTop( true ); This won't work when I'm starting a game in fullscreen mode. I know you normally don't want your windows to stay on…
user238801
10
votes
2 answers

How does JTable RowFilter work?

I'm try to create a Row filter for a JTable to limit the number of rows displayed in the table. The RowFilter code is simple. It converts the model row number to the view row number (in case the table is sorted) and then checks if the view row…
camickr
  • 321,443
  • 19
  • 166
  • 288
10
votes
4 answers

Swing verify code on Event Dispatch Thread at runtime

Are there any libraries that instrument code to verify that methods called on Swing components are called on the Event Dispatch Thread? It probably wouldn't be too difficult to write some basic code for doing this, but I'm sure there are edge cases…
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
10
votes
3 answers

JTable - Getting a cell into Edit mode on pressing Tab

This is possibly has a trivial solution, but I am at the end of my tether so I hope somebody can help out. I use a JTable which has a custom renderer and a custom editor for a set of columns. The renderer uses a JLabel component and the editor uses…
Luhar
  • 1,859
  • 2
  • 16
  • 23
10
votes
6 answers

How to display an image in a Java application

I want to display an image in my Java application. I found a code to download the image from the webserver and show it in the jframe. I want to use a label to show the image or something else. It shouldn't be JFrame. Here is my code: Image image =…
Nubkadiya
  • 3,285
  • 13
  • 40
  • 45
10
votes
3 answers

Best way to implement game loop without freezing UI thread

I'm trying to make a simple 2D game in Java. So far I have a JFrame, with a menubar, and a class which extends JPanel and overrides it's paint method. Now, I need to get a game loop going, where I will update the position of images and so on.…
Matthew H
  • 5,831
  • 8
  • 47
  • 82
10
votes
3 answers

How to use Map element as text of a JComboBox

I am populating a JComboBox (using addItem()) with all the elements of a collection. Each element in the collection is a HashMap (so its a ComboBox of Hashmaps..). My question is - Given that I need each item to be a HashMap how do I set the text…
llm
  • 5,539
  • 12
  • 36
  • 30
10
votes
2 answers

java.lang.IllegalStateException while using Document Listener in TextArea, Java

DocumentListener dl = new MessageDocumentListener(); ((AbstractDocument) nboxArea.getDocument()).setDocumentFilter(new DocumentFilter() { public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws…
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
10
votes
3 answers

How to add support for resizing when using an undecorated JFrame?

I would like to customize my titlebar, minimize-, maximize- and the close-button. So I used setUndecorated(true); on my JFrame, but I still want to be able to resize the window. What is the best way to implement that? I have a border on the…
Jonas
  • 121,568
  • 97
  • 310
  • 388
10
votes
3 answers

Is there a Swing component for Google Maps?

I would like to have support for Google Maps in my Java Swing desktop application. Is there an Google Maps component for Swing that is freely available? It would be good if it was extendable and maybe had support for other maps i.e. like…
Jonas
  • 121,568
  • 97
  • 310
  • 388