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
3 answers

Java getting download progress

I am writing a Java application (Using NetBeans as an IDE and a jFrame form), and one part of it downloads a file. How can I update a progress bar with the current progress of the download, or at least get the total amount of currently downloaded…
deejay31
  • 105
  • 1
  • 1
  • 7
10
votes
5 answers

How to set the RowHeight dynamically in a JTable

I want to put a String in a JTable that is longer than the given cell-width. How can I set the rowHeight dynamically so that I can read the whole String? Here is an example: import javax.swing.*; public class ExampleTable { public JPanel…
Ramses
  • 652
  • 2
  • 8
  • 30
10
votes
1 answer

swing: appropriate Listener for JTextField change events

Which type of Listener do I use for listening to changed text events in a JTextField? (I should know this or be able to tell from the Javadoc but I can't seem to figure it out.)
Jason S
  • 184,598
  • 164
  • 608
  • 970
10
votes
3 answers

Is there any way to force GridLayout to leave empty cells?

I have a JTabbedPane with 2 JPanels set to GridLayout(13, 11). The first JPanel has enough of the cells filled out that it leaves the empty cells. The second JPanel has significantly fewer cells filled and this results in each button getting…
Pentarctagon
  • 413
  • 2
  • 5
  • 12
10
votes
3 answers

Open-source improvements or replacements for Swing components

I develop a number of desktop Java applications using Swing, and while Swing is quite powerful (once you get the hang of it), there are still a lot of cases where I wish some advanced component was available right out of the box. For example, I'd…
David Koelle
  • 20,726
  • 23
  • 93
  • 130
10
votes
0 answers

Embedding a native window inside a JFrame

Does anyone know of a method or API that supports embedding a native window inside either a Java JFrame or JPanel? I found this previous post: How do I run an external program inside a Java frame in netbeans in a platform independent manner? I can…
Graham Seed
  • 742
  • 3
  • 10
  • 24
10
votes
1 answer

Windows 7 Touch Screen + Java Swing = Delayed Mouse Events

I am developing a Swing application in Java. The program is to be run on dedicated Windows 7 Touch Screen machines, and as far as I know, this program should be the only thing running on them under normal operation. I've noticed that Windows 7's…
Tustin2121
  • 2,058
  • 2
  • 25
  • 38
10
votes
2 answers

Overriding getPreferredSize() breaks LSP

I always see advices in this site of overriding getPreferredSize() instead of using setPreferredSize() as shown in these previous threads for example. Use of overriding getPreferredSize() instead of using setPreferredSize() for fixed size…
nachokk
  • 14,363
  • 4
  • 24
  • 53
10
votes
2 answers

What are the benefits to painting on a JPanel vs. JComponent?

So in a recent answer, someone commented this (in regards to painting): "This is probably some kind of illness of 90% of Swing Programmers: When they make their own component, they always extend JPanel instead of JComponent. Why?" I'm still fairly…
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
10
votes
2 answers

JFrame freezes on Windows 8.1 when resized

Also posted on coderanch.com. import javax.swing.*; public class Tmp { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JFrame…
Pawel P.
  • 3,731
  • 4
  • 20
  • 20
10
votes
4 answers

Excel spreadsheet like library in Swing (=improved JTable)

I'm searching for a free, open-source if possible, Java swing library that improves the existent JTable (which is very simple). I want to do an application with a spreadsheet similar to Excel one. Without the formula but with copy/paste…
Damien
  • 583
  • 3
  • 7
  • 18
10
votes
2 answers

Java automatically adjusting to the Windows 7 font size adjustment

In Windows 7, if you change the font size via the Control Panel->Appearance and Personalization -> Display "Make text and other items larger or smaller", it adjusts not only the menu sizes, but also the text content size of apps like Notepad,…
Glenn
  • 101
  • 1
  • 3
10
votes
3 answers

Java Swing : JSplitPane split two component equals size at start up

I'm using JSplitPane includes two JScrollPane at each side. I don't know how to make them at equals size at start up. Here is my main code: contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); …
hqt
  • 29,632
  • 51
  • 171
  • 250
10
votes
1 answer

JTable - ActionListener for select a row

I need the right AcionListener for my JTable. At program start there is no row selected by default. If I now select any row in this JTable then the ActionListener shall start.
user3057184
  • 133
  • 1
  • 1
  • 8
10
votes
4 answers

Rotating Image with AffineTransform

I have got class called Airplane. Inside this class i have got variable img which is a BufferedImage type. What is more i have got class WorldMap which overrides function paintComponent(Graphics g): @Override public void paintComponent(Graphics g)…
user2410128
1 2 3
99
100