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

How can I make a button exactly the same size of its text?

Is it possible to make a JButton take exactly the size of its text? Since by default, a JButton will have a small amount of padding (both horizontal and vertical) around its text. I would like to remove that padding.
PB_MLT
  • 834
  • 3
  • 13
  • 30
10
votes
8 answers

Java Swing - JCheckbox with 3 states (full selected, partially selected and deselected)

I want a JCheckbox that has 3 states as shown below: Partially Selected Unselected Full Selected Q1. Can I use the JCheckbox for the above purpose or have to go for some custom swing component?
Amit
  • 33,847
  • 91
  • 226
  • 299
10
votes
5 answers

System.exit(0) in java

I am writing an application program using swing. I need to exit from the application by clicking the JButton for that can i use System.exit() or should i use some other methods, which is the best practice. If calling System.exit() is not best…
Ram
  • 254
  • 1
  • 7
  • 20
10
votes
2 answers

Alternative to JFileChooser on Linux?

I don't like this ugly FileChooser layout in Linux. This layout is used by any other program and is MUCH more beautiful. Is this layout available in Java? If so, how?
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
10
votes
4 answers

Workaround for Slow Java Swing Menus

In Java 7 and 8 there is a bug in Swing menus that causes it to be slow when running an application remotely over X11 while other X11 applications are running. This issue was introduced in Java 7 and has never been fixed. Does anyone have any…
Tom Pelaia
  • 1,275
  • 10
  • 9
10
votes
4 answers

How can I create a JTable where the first column is always in the JScrollPane viewport?

What's the best way to set up a table in a JScrollPane such that the first column is always on the screen in the same position regardless of horizontal scrolling and overlaps columns that pass underneath? When the scrollbar is at the farthest…
voodoogiant
  • 2,118
  • 6
  • 29
  • 49
10
votes
1 answer

Java mouse motion anywhere on screen

I'm sure this is possible but all my searching is coming up blank. In Java is it possible to register for a mouse motion event outside of a Java app? So if the mouse pointer moves anywhere on the screen I get a call back. An approximation is…
David
  • 1,862
  • 2
  • 22
  • 35
10
votes
8 answers

How do I delete an object referenced by a dialog?

I created a dialog with a jpanel inside it, and that jpanel will be still referenced if I get rid of the dialog. I want to destroy that dialog and everything in it when I click a cancel button. How do I delete both the dialog and the jpanel?
joseph
  • 687
  • 3
  • 12
  • 21
10
votes
2 answers

Frame always on top of my program only

I'm trying to create a kind of toolbar in an undecorated alwaysOnTop frame. Thus, I want my frame to be on top of my main frame, but not on top of frames from other programs. I tried this code : public class Test { private static JFrame…
Sharcoux
  • 5,546
  • 7
  • 45
  • 78
10
votes
3 answers

Clear the session/cache/cookie in the JavaFX WebView

I had a Swing dialog, which uses JavaFX WebView to display oAuth 2.0 URL from Google server. public class SimpleSwingBrowser extends JDialog { private final JFXPanel jfxPanel = new JFXPanel(); private WebEngine engine; private final…
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
10
votes
7 answers

GUI guidelines for swing

Is there a resource where GUI design for swing is explained? Like best practices and such.
Carlos Blanco
  • 8,592
  • 17
  • 71
  • 101
10
votes
3 answers

JTextArea and JTextField internal padding on text

I would like to increase the spacing / padding / insets for the JTextField and JTextArea. Effectively increase the spacing between the two red lines in the image below:
n002213f
  • 7,805
  • 13
  • 69
  • 105
10
votes
6 answers

Java: Look and Feel

I am using Netbeans on a Windows machine, what happens is that if I run the main java file the look and feel I get is different than in the case I run the whole program. Meaning if I do this: I get But if I do this I get Did you see the…
Daksh Shah
  • 2,997
  • 6
  • 37
  • 71
10
votes
4 answers

Browser using JEditorPane forcing blue background

This is the code I'm using to display google in a JEditorPane String url="http://google.com"; editorPane.setEditable(false); try { editorPane.setPage(url); } catch (IOException e) {} But for some reason the background will…
DGK
  • 2,947
  • 5
  • 32
  • 47
10
votes
5 answers

JLabel not greyed out when disabled, when HTML text displayed

How do I get a JLabel displaying a HTML string to appear greyed out (which is the behaviour of JLabels that don't display HTML text)? Is there another way than actually changing the colour myself by modifying the foreground property? JLabel label1 =…
bguiz
  • 27,371
  • 47
  • 154
  • 243