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
81,382
questions
551
votes
9
answers
150k
views
The Use of Multiple JFrames: Good or Bad Practice? [closed]
I'm developing an application which displays images, and plays sounds from a database. I'm trying to decide whether or not to use a separate JFrame to add images to the database from the GUI.
I'm ...
507
votes
9
answers
69k
views
Should I avoid the use of set(Preferred|Maximum|Minimum) size methods in Java Swing?
Several times I've been criticized for having suggested the use of the following methods:
setPreferredSize()
setMinimumSize()
setMaximumSize()
on Swing components. I don't see any alternatives to ...
372
votes
14
answers
1.2m
views
How to add an image to a JPanel?
I have a JPanel to which I'd like to add JPEG and PNG images that I generate on the fly.
All the examples I've seen so far in the Swing Tutorials, specially in the Swing examples use ImageIcons.
I'm ...
296
votes
16
answers
706k
views
How to programmatically close a JFrame?
What's the correct way to get a JFrame to close, the same as if the user had hit the X close button, or pressed Alt + F4 (on Windows)?
I have my default close operation set the way I want, via:
...
251
votes
15
answers
411k
views
Value Change Listener to JTextField
I want the message box to appear immediately after the user changes the value in the textfield. Currently, I need to hit the enter key to get the message box to pop out. Is there anything wrong with ...
250
votes
9
answers
235k
views
What is the difference between Swing and AWT?
Can someone please explain me what's the difference between Swing and AWT?
Are there any cases where AWT is more useful/advised to use than swing or vice-versa?
236
votes
12
answers
382k
views
How to set JFrame to appear centered, regardless of monitor resolution?
While working with Java, I find it hard to position my main window in the center of the screen when I start the application.
Is there any way I can do that?
It doesn't have to be vertically centered, ...
231
votes
5
answers
258k
views
Java Swing revalidate() vs repaint()
I'm putting together a Swing application where I often want to replace the contents of a JPanel. To do this, I'm calling removeAll(), then adding my new content, then calling revalidate().
However I'...
226
votes
9
answers
760k
views
Java GUI frameworks. What to choose? Swing, SWT, AWT, SwingX, JGoodies, JavaFX, Apache Pivot? [closed]
There is quite a lot of gui frameworks out there for java, but what is recognized as today's framework of choice?
The following is my understanding of the different frameworks, please correct me if ...
211
votes
6
answers
250k
views
Swing vs JavaFx for desktop applications [closed]
I have a very big program that is currently using SWT. The program can be run on both Windows, Mac and Linux, and it is a big desktop application with many elements.
Now SWT being somewhat old I would ...
194
votes
7
answers
162k
views
Copying text to the clipboard using Java
I want to copy text from a JTable's cell to the clipboard, making it available to be pasted into other programs such as Microsoft Word. I have the text from the JTable, but I am unsure how to copy it ...
192
votes
1
answer
228k
views
DTO and DAO concepts and MVC [closed]
Why do we use DTO and DAO, and when should we use them. I am developing a GUI Java software to do with inserting, editing, deleting data. But I am struggling to distinguish between DTO/DAO and Model, ...
176
votes
6
answers
65k
views
Providing white space in a Swing GUI
A GUI with no white space appears 'crowded'. How can I provide white space without resorting to explicitly setting the position or size of components?...
174
votes
8
answers
392k
views
JComboBox Selection Change Listener?
I'm trying to get an event to fire whenever a choice is made from a JComboBox.
The problem I'm having is that there is no obvious addSelectionListener() method.
I've tried to use actionPerformed(), ...
167
votes
4
answers
240k
views
How do I set a JLabel's background color?
In my JPanel, I set the background of a JLabel to a different color. I can see the word "Test" and it's blue, but the background doesn't change at all. How can I get it to show?
this.setBackground(...