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,372
questions
0
votes
0
answers
9
views
How to read Objects in a PDF file with Apache PdfBox in Java?
I'm developing a pdf reader/editor program in Java using Swing for UI with Apache PdfBox. I want to get the objects and their states in each of the pdf pages. I mean the text, images, shapes as ...
0
votes
0
answers
29
views
I need help making sure my code is thread safe
So I am trying to use SwingWorkers in my application (written in Java) where I collect some data from an API and display it in the app's GUI. Please keep in mind that I am very unsure when it comes to ...
0
votes
0
answers
22
views
Updating callers of PropertyChangeListener in Java + Swing
I'm working with Swing and PropertyChangeListener to manage theme changes in an application. Listeners are notified when the theme property changes in the ThemeManager class. However, I need a ...
0
votes
0
answers
20
views
Java swing scrollpane get all component in horizontally
I am making an e-commerce application. In my dashboard frame I have a search panel one product keeper scroll-panel and one menu panel. I want that all my fetched products can be stored inside product ...
0
votes
0
answers
21
views
How do I configure my WSL to make resizeable work for tkinter or swing?
I tried to make a window in both Java and Python, both Swing and TKinter have a method that blocks resizing but it doesn't work if I'm running in WSL. Is there any way to fix this?
I tried using ...
-1
votes
1
answer
26
views
Resize JPanel with animation
I want to make a panel that, when the mouse enters it, its height increases smoothly and when the mouse leaves it, its height decreases smoothly.
public class Main {
private static final int ...
-2
votes
0
answers
39
views
lines appears below the panel in java swing [closed]
I'm developing a snake and ladder game using Java Swing. I am trying to draw lines (representing snakes and ladders) under JPanel or JLabel components, but I'm encountering issues with setting the Z-...
-1
votes
0
answers
38
views
How to trigger ItemListener by JCheckBox setSelected(false)?
I found this answer which states that ItemListener#itemStateChanged is useful as it is invoked when pragmatically setting the JCheckBox by setSelected(true). However, this doesn't apply for the case ...
-1
votes
1
answer
34
views
How to set image size in JTextPane with HTML and CSS (Java, Swing)?
I want to insert an image (say - a formula compiled from LaTeX) into JTextPane, using HTML+CSS for text markup, manually setting it's size. I tried like here
import java.awt.Dimension;
import javax....
0
votes
1
answer
32
views
How can I make the tabs in the menu bar with rounded corners and margins in Java/Swing using FlatLaf Theme Editor?
I'm creating a Java application with Swing as the GUI. I'm using FlatLaf themes FlatLightLaf.
On the JMenuBar I want to create something like this:
VSCode Title Bar
But I end up with something like ...
-3
votes
0
answers
32
views
Java Swing application getting significantly increasingly slower with each object creation [closed]
So basically my application is a JPanel which I'm adding Jlabels to and the labels are moving around. After adding about 20 labels the app is unusably slow. The labels are set to move 60 times per ...
-1
votes
1
answer
37
views
How to use a TableCellRenderer to display an object in a table in Swing
I'm making a todolist app and I'm displaying all the tasks on a JTable(which only has one row), I also added a RowFilter to the JTable inorder to sort the tasks based on different categories. I ...
-1
votes
0
answers
31
views
Adding margin to the panel inside a JScrollPane
I have a panel with a BoxLayout layout and I want this panel to have a scrollbar, so I made a JScrollPane. But when I use JScrollPane, the emptyBorder that I add is not added to my panel
JPanel panel =...
-1
votes
0
answers
24
views
What is the purpose of `labelFor` in a view xml in Java Swing [duplicate]
So I am using the Swing UI designer for the first time and while editing JLabel for my JTextField I came by labelFor field.
After clicking the arrow on the side it indeed displayed my currently ...
-1
votes
0
answers
31
views
Java Swing: How to show icon in scrollable panel [duplicate]
I am new to Java and Swing. I want to use jlatexmath library to render latex formula. But sometimes the formula is very long and the equation goes out of the JLabel (i.e., displayArea).
JLabel ...
-1
votes
1
answer
90
views
"Flowing" JToolBar
Here's my goal: to make a toolbar with buttons that "flow" down once the window is shrunk far enough. It should not be shy about nudging the sibling below if necessary
How do I do it?
Here's ...
0
votes
0
answers
46
views
How to open a new frame when I clicked a button? Is my code a “bad” code? Java GUI Swing
I’m making a frame with numerous buttons inside.
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("Change Name")){
changeNameGUI.setVisible(true);
...
2
votes
0
answers
89
views
Black background of copied and pasted image Java Swing
I try to copy a molecule image in ChemDraw (it is like Incscape to draw molecules) and paste it to my Swing GUI. I use something like that.
import java.awt.*;
import java.awt.datatransfer.*;
import ...
-2
votes
1
answer
41
views
Why doesn't this code swap images, as intended, when I press any key?
My program is intended to display 2 panels initially with different images from file Z_pic1.png and Z_pic2.png.WHEN ANY KEY IS PRESSED the displays on the panels should interchange swap. It is not ...
-1
votes
0
answers
44
views
paintMethod not working as intended. Draw method will never call even when manually tried [duplicate]
I am just trying to get the paintComponent method from the LocateMap class to run. currently it never runs.
I am trying to draw a set number of images within a jpanel based on the dimensions given ...
0
votes
1
answer
42
views
"Stretchable" JLabel with dynamic text
I don't like scrollbars for their clumsiness. I wrote a custom JLabel extension that dynamically trims the label's text on each paint() call and appends with an ellipsis
package StretchableLabel;
...
1
vote
1
answer
52
views
Display adjacent Java Swing Polygons without gap even when using antialiasing
Using antialiasing in filling adjacent polygons in Java Swing can result in a fine gap between the polygons. The gap can be closed when using drawPolygon in addition to fillPolygon, but the polygon is ...
1
vote
0
answers
54
views
Best Java Swing layout manager for proportional panes, etc. heights [closed]
I want to keep the proportions for various JPane sizes upon resizing the window (e.g. 10% text box, 90% text pane, etc.) in order for complete consistency. I've been using JSplitPanes as a stopgap, ...
0
votes
1
answer
48
views
How to pause execution for X milliseconds in AWTEventQueue
I have a game where I want to flash a component a red color, and then back to its normal color after a short delay. Obviously, I could just do Thread.sleep(123), but that is EXTREMELY undesirable ...
0
votes
0
answers
27
views
Icon-only JButtons layering the icon of the most recently clicked JButton when clicked [duplicate]
I'm using java swing components to build up a goofy, very simple RPG java app, and I've run into this weird behavior where when I click on a JButton, it duplicates the icon of JButtons I've pressed ...
0
votes
0
answers
40
views
How to open a JFileChooser with the file sort being last modified?
I want to open a JFileChooser with the sorting option being set to modified descending by default.
Anyone have any ideas?
(I'm relatively new to swing)
Cheers
I've found this older solution but it ...
0
votes
1
answer
45
views
How to make translucent image in Java with swing?
I am making a game using Java's swing.
There is a part during the game where a certain image needs to be exposed on the screen with 50% transparency, but I don't know how to make that image ...
0
votes
1
answer
53
views
Java Mail Mailgun GUI project attaching images and not embedding them
This is the first time I've written something in Java so I'm leaning slowly but I am hard stuck on how to fix this issue. I'm having an issue getting the images that a user inserts into my JEditorPane ...
-1
votes
1
answer
48
views
How do I scale or set the the size of an ImageIcon in Java?
I can not find a way to set the size of an ImageIcon placed in a JLabel. I i.e. want to load image with size 32x32, but paint in size of 16x16 pixel (or 144 dpi).
I can no where find a way to set the ...
-1
votes
0
answers
40
views
Issue with my Music Equalizer java program not doing anything when I open a .mp3 file
Image of ProgramI'm working on a Java Swing application that includes a music equalizer. The application is supposed to allow users to select an MP3 file and visualize the audio levels in real-time. ...
0
votes
0
answers
54
views
Java Swing Custom zoom Panel
I am experiencing an issue with the zoom panel action in Java Swing. I have customized a class ZoomableJPanel to zoom innerPanel, but the ZoomableJPanel does not correctly handle zooming, causing the ...
0
votes
0
answers
35
views
How do you make JScrollPane fill multiple rows in GridBagLayout?
I have a JScrollPane that has a JTextArea in it. I also have a JPanel panel = new JPanel(new GridBagLayout) and a GridBagConstraints constraints = new GridBagConstraints() and this GridBagLayout is a ...
1
vote
2
answers
66
views
Java JSCrollPane won't resize below minimum size of JButton with text
I'm trying put a JPanel (GridLayout 0, 1) with JButtons it, within the ViewPort of a JScrollPane. This is easy enough to do, but it doesn't behave "properly" when resizing the parent JFrame....
0
votes
2
answers
88
views
How can I install java Swing in 2024 (for eclipse)?
In the past I have made graphical interfaces with Java Swing. On my new computer I have tried to install java Swing but I have not found how to do it. I have searched in eclipse marketplace but it ...
0
votes
2
answers
44
views
How to display a popup menu during a drop operation
I have an application where I allow strings to be dragged and dropped on to one of the components. This works fine.
Now I want to be able to add customization options to this operation. My first ...
1
vote
1
answer
71
views
How can I do a progressive bar with JProgressBar from Swing on Java?
I'm a beginner on parallel computing. I've been working on Java in Apache Netbeans. My recent work was about semaphores, using the Semaphore and Thread Java classes, in that sense, I had to make a ...
1
vote
0
answers
59
views
Can I somehow tell apart user-triggered clicks and programmatic ones?
When a dialog window is first opened, I need to programmatically select an option (a JRadioButton) and do X
When the user selects an option, I need to do Y
X is a subset of Y
In both cases, the radios ...
-1
votes
0
answers
40
views
Transparent JToolTip background outside frame in Linux
I'm working on a Java swing application (I'm using JDK 22) where I customize basically every GUI component.
The problem I'm facing is that I've made a custom tooltip UI class where I paint it as a ...
-1
votes
0
answers
102
views
Intercept OK dialog disposals
I am about to write custom interceptors for our JDialog extension that intercept "ok" dialog closures and could veto them. It's going to be a functional interface returning boolean
But what ...
0
votes
1
answer
34
views
My components in two different panels are too small and don't fit to the frames size, how can I fix this?
I made a JFrame (size: 500 , 600) that uses GridBagLayout to place two JPanels (one using GridLayout and the other using GridBagLayout) on top of each other; however, when I run my JFrame the ...
0
votes
1
answer
70
views
Adaptable size of a CardLayout-managed panel
While using CardLayout, I encountered a small problem with its size
If I don't set a preferred size explicitly (or set it to null), CardLayout seems to set preferred size of its managed container to ...
1
vote
0
answers
28
views
Make one column weigh double as much as another column inside GridLayoutManager on the IntelliJ GUI designer
Is it possible to make it so that two columns which both have the "Want grow" property in the GridLayoutManager take up different proportions?
As in like, instead of them both taking equally ...
-1
votes
0
answers
72
views
Swing's ItemEvent: difference between getItem() and getItemSelectable()
In the context of java.awt.event.ItemEvent, what is the difference between getItem()
Returns the item affected by the event.
and getItemSelectable()?
Returns the originator of the event.
Here's a ...
1
vote
1
answer
44
views
Issues with Panels not displaying in basic Swing application
I wanted to add a panel to this basic swing application however it is affecting the program from displaying properly. Could I get help as to why?
package welcome.netbeans;
import java.awt....
0
votes
2
answers
78
views
Java Swing rendering inconsistencies and flickering
I'm trying to familiarize myself with making GUIs in java and wrote a program that should move a square on the screen depending on WASD key inputs (Following an online tutorial).
However, when running ...
0
votes
0
answers
54
views
JFileChooser opening in background [duplicate]
I have a problem with the JFileChooser. When I call it in the main class, it opens in the foreground without any problems. But if I want to call it via another method, it opens in the background. How ...
0
votes
0
answers
55
views
Place the caret at the beginning of the JTextArea after pasting text
I would like the caret of a JTextArea to be positioned at the beginning of the first line after pressing CTRL+V. I have tried this code but it does not work, however, I noticed that by replacing the ...
0
votes
1
answer
47
views
GUI Designer form file is not rendered
We have a lot of IntelliJ IDEA GUI forms in our project. A few of them are broken (for years). I decided to fix it. I know it is discouraged to manually edit those XML files, but here we are. I don't ...
-1
votes
1
answer
87
views
Deleting current controls in java
OK, let's try this. This a small Java application to dynamically create JButtons. What I am trying to find a way to do is fully delete created JButtons so the garbage collection will free up the ...
0
votes
1
answer
76
views
FileNotFoundException thrown only for .mp3s but not for .png
I'm developing a game in Swing, where I'd like to use both audio and image assets. My issue is that, while opening the .png images works fine, opening my .mp3 file always throws a ...