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

How to set transparent background of JDialog

Hy,.. how can i set the background transparent and "remove" the closeoperation (marked red) ? I only want to show the card :-) Thanks..!
Christian 'fuzi' Orgler
  • 1,682
  • 8
  • 27
  • 51
10
votes
1 answer

How to repaint a JPanel after have drawn on it?

I have a component that inherits from JPanel, I draw a grid on it. Now I have a JComboBox and I want the user to be able to choose the grid size here and then press a button to make the grid change (repaint the grid). The thing is that it paints the…
Aerozeek
  • 495
  • 1
  • 3
  • 11
10
votes
2 answers

Android Studio gradle can't import groovy.swing.SwingBuilder

I'm using this technique to make release builds ask for keystore passwords, but lately the Android Studio editor for build.gradle complains: Cannot resolve symbol 'groovy' for the line: import groovy.swing.SwingBuilder It didn't used to complain.…
Jerry101
  • 12,157
  • 5
  • 44
  • 63
10
votes
1 answer

jdk 9 high dpi disable for specific panel

With JDK 9 my swing app works well on Windows with 4k highdpi and normal 1080p normal dpi. Labels, Comboboxes etc. all look nice and are scaled up on the 4k screen. But so is my JPanel where i draw custom images. Can i disable the scaling for this…
Philipp König
  • 357
  • 2
  • 10
10
votes
3 answers

Shortcut key for jButton without using alt key

In SWT you can give any button a shortcut key simply by adding & in front of the letter in the button label. For example, if my button label is &Play, I can activate the button by hitting letter p on the keyboard. In Swing, you can add a shortcut…
Rich C
  • 3,164
  • 6
  • 26
  • 37
10
votes
2 answers

JComboBox popup appears and hide immediately when clicking on its border (Bad User Experience)

When you have a swing JComboBox and click on its border, the popup appears and disappears immediately. When I say click, I mean press the left button of the mouse and release immediately. It may be considered a bad user experience because no user…
viniciussss
  • 4,404
  • 2
  • 25
  • 42
10
votes
1 answer

Java swing animation looks choppy. How to make it look pro?

UPDATE: semicomplex animation + swing timer = trainwreck. The ultimate source of the problems was the java timer, either the swing or utility version. They are unreliable, especially when performance is compared across operating systems. By…
comp sci balla
  • 823
  • 2
  • 13
  • 29
10
votes
1 answer

access mtp device with java

I have developed a small application that copies files from a folder to another.I use a JFileChooser to select the target directory.Something I hadn't tried for a long time is to select my phone as the target directory.I tried but I couldn't find it…
cssGEEK
  • 994
  • 2
  • 15
  • 38
10
votes
4 answers

execute SwingWorker multiple times

I want to be able to use SwingWorker subclass multiple times. Is this possible? I have read in the java doc: SwingWorker is only designed to be executed once. Executing a SwingWorker more than once will not result in invoking the doInBackground…
Feras Odeh
  • 9,136
  • 20
  • 77
  • 121
10
votes
3 answers

How to prevent JPopUpMenu disappearing when checking checkboxes in it?

I want to use JCheckBoxMenuItems in a JPopupMenu. It works, but the problem is that the popup menu disappears when a checkbox item has been checked or unchecked. So if one wants to check/uncheck several items, the popup needs to be launched…
Joonas Pulakka
  • 36,252
  • 29
  • 106
  • 169
10
votes
4 answers

java swing vs mvc: is this pattern indeed possible?

I am new in swing, but managed to create a descend gui. My problem though is that I was not able to apply the patterns suggested in references/tutorials, mainly the MVC pattern. Is it me, or in JTree and using SwingWorker, it is not possible to have…
Cratylus
  • 52,998
  • 69
  • 209
  • 339
10
votes
1 answer

Java Swing application under Gnome - use Adwaita (dark skin) window title bar

Is there a way for a Java Swing desktop application that runs in Gnome (3.14) on Linux (Debian) to make Gnome use the dark-themed (Adwaita) version of the window decoration? I am using a custom dark Swing look-and-feel, and the only thing that is…
0__
  • 66,707
  • 21
  • 171
  • 266
10
votes
5 answers

Java Dynamically Loading a class

I am attempting to load classes dynamically into a component. I am using a file chooser to select the .JAR file that will be loaded and then a option pane to get the name of the class. I have trawled the internet looking for how to convert a java…
Rumpleteaser
  • 4,142
  • 6
  • 39
  • 52
10
votes
5 answers

Busy loop in other thread delays EDT processing

I have a Java program which executes a tight loop on a separate (non-EDT) thread. Although I would think the Swing UI should still be responsive, it is not. The example program below exhibits the problem: clicking the "Try me" button should pop up a…
davmac
  • 20,150
  • 1
  • 40
  • 68
10
votes
1 answer

SwingController get page coordinate

Using IcePdf (ver 1.8) i integrate a SwingController into my JPanel to use it in my application. Since the page displayed into the SwingController is in a specific position into the controller. How can i obtain the coordinate of the page (top left…
Razlo3p
  • 455
  • 2
  • 7
  • 28