Skip to main content

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
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 ...
Peddler's user avatar
  • 6,085
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 ...
Heisenbug's user avatar
  • 39k
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 ...
Leonel's user avatar
  • 29k
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: ...
JustJeff's user avatar
  • 12.9k
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 ...
user236501's user avatar
  • 8,608
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?
Samiksha's user avatar
  • 6,162
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, ...
AmateurProgrammer's user avatar
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'...
William's user avatar
  • 13.6k
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 ...
Quillion's user avatar
  • 6,416
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 ...
user765134's user avatar
  • 1,943
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, ...
Hoody's user avatar
  • 3,022
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?­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­...
Andrew Thompson's user avatar
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(), ...
Allain Lalonde's user avatar
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(...
Catalina Island's user avatar

15 30 50 per page
1
2 3 4 5
5426