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
163
votes
4 answers

Java Look and Feel (L&F)

I am developing a desktop application with Java Swing for my personal use.I am in need of some beautiful Look and Feel for my application. How can I do it using Java or a 3rd party API?
rajesh
  • 1,773
  • 3
  • 12
  • 6
163
votes
12 answers

How can I get screen resolution in java?

How can one get the screen resolution (width x height) in pixels? I am using a JFrame and the java swing methods.
AndreDurao
  • 5,600
  • 7
  • 41
  • 61
158
votes
10 answers

Java Desktop application: SWT vs. Swing

I'm a web developer at day and thinking about building my first real desktop application. The idea is to build a tool that automates a very repetitive task in a web application where no API is available. I know I want to use Java. I used it before…
janpio
  • 10,645
  • 16
  • 64
  • 107
157
votes
4 answers

Difference between java.exe and javaw.exe

Recently I noted that some applications are running on javaw (not in java). What is the difference between them and how can I run my Swing application on javaw?
asela38
  • 4,546
  • 6
  • 25
  • 31
152
votes
6 answers

How to present a simple alert message in java?

Coming from .NET i am so used calling Alert() in desktop apps. However in this java desktop app, I just want to alert a message saying "thank you for using java" I have to go through this much suffering: (using a JOptionPane) Is there an easier way?
Haoest
  • 13,610
  • 29
  • 89
  • 105
136
votes
20 answers

How to center a Window in Java?

What's the easiest way to centre a java.awt.Window, such as a JFrame or a JDialog?
Andrew Swan
  • 13,427
  • 22
  • 69
  • 98
134
votes
14 answers

JFrame in full screen Java

I will be doing a project soon and I will have to use full screen mode in it. It will draw some graphics in the window. It would be convienient if I use JFrame or something similar. I don't know what the final resolution of the screen will be.…
Yoda
  • 17,363
  • 67
  • 204
  • 344
133
votes
2 answers

GUI not working after rewriting to MVC

I'm practicing MVC style programming. I have a Mastermind game in a single file, working fine (maybe apart of the fact that "Check" button is invisible at start). http://paste.pocoo.org/show/226726/ But when I've rewritten it to model, view,…
trevor_nise
  • 1,357
  • 2
  • 9
  • 3
131
votes
2 answers

How to best position Swing GUIs?

In another thread I stated that I liked to center my GUIs by doing something like this: JFrame frame = new JFrame("Foo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new…
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
131
votes
1 answer

What GUI libraries are the JetBrains using?

Background I am somewhat new to Java and am enjoying using IntelliJ IDE developed by the JetBrains team. I have downloaded the source for the Community Edition, and I am trying to work out what GUI libraries they are using to get the…
Levi Putna
  • 2,863
  • 6
  • 30
  • 47
127
votes
4 answers

error upon assigning Layout: BoxLayout can't be shared

I have this Java JFrame class, in which I want to use a boxlayout, but I get an error saying java.awt.AWTError: BoxLayout can't be shared. I've seen others with this problem, but they solved it by creating the boxlayout on the contentpane, but that…
Ulrik
127
votes
8 answers

How to change JFrame icon

I have a JFrame that displays a Java icon on the title bar (left corner). I want to change that icon to my custom icon. How should I do it?
Anand
  • 10,310
  • 24
  • 90
  • 135
125
votes
12 answers

Best GUI designer for eclipse?

I'm looking for a good GUI designer for swing in eclipse. My preference is for a free/open-source plugin.
jumar
  • 5,360
  • 8
  • 46
  • 42
123
votes
2 answers

Difference between validate(), revalidate() and invalidate() in Swing GUI

Swing components have multiple methods related to updates of screen layout, in particular: validate() invalidate() revalidate() The Java documentation defines these somewhat from a technical perspective, but it's not particularly clear how they…
mikera
  • 105,238
  • 25
  • 256
  • 415
123
votes
4 answers

JPanel Padding in Java

I have a formatting question for my Java swing application. It should be fairly straightforward, but I am having difficulty finding any aid (Every topic seems to be regarding removing any default padding in JPanel). The text in my various JPanels…
Connor
  • 1,943
  • 5
  • 16
  • 13