Most voted "swing" questions
Swing is a Toolkit widget for use with Java, compatible with the Abstract Window Toolkit (AWT). Use this tag for questions regarding components or classes related to the development of graphic applications using this API.
Learn more…749 questions
Sort by count of
-
28
votes2
answers1666
viewsWhy should the main method dispatch the creation of the GUI to the EDT in a swing application?
According to the Java specification, much of the Swing API is not Thread-Safe and shall rotate in the Event Dispatch Thread. Like, after initializing the GUI events are fired from within of the EDT…
-
21
votes1
answer1341
viewsHow to remove the edges of a Jframe?
I’d like to remove the edges of a JFrame. I used setUndecorated(true), however it removes completely and I would like to leave only the title bar of the JFrame.…
-
19
votes2
answers1128
viewsWhat is the difference of use between Keypressed and Actionperformed?
I ran some tests to see the difference in use, and apparently they both go off under pressure ENTER on the keyboard, as can be seen in the example below: import java.awt.*; import java.awt.event.*;…
-
13
votes1
answer1056
viewsWhat are layout managers and why should they be used?
When a graphical interface with the API is being developed swing of java, end up having to mess with the positioning of components on the screen, which induces us to learn about layout managers so…
-
12
votes2
answers490
viewsWhy is it not recommended to use Defaulttablemodel?
I searched some sites about how to fill a table in java and many suggested to avoid the DefaultTableModel? Why should one avoid using this class for more complex object cases? What does its use…
-
11
votes1
answer4373
viewsHow to popular a Jtable with own Tablemodel?
When you’re messing with swing, we almost always come across having to handle tables and populate them with some kind of information. For simpler situations, the DefaultTableModel resolves, but when…
-
11
votes1
answer673
viewsDetect collision between corners of objects
I’m writing a game based on Breakout, but I can’t think of a way to detect the collision between the corner of the ball area and the paddle, so I can reverse the horizontal direction of the ball. In…
-
10
votes3
answers28595
viewsCalculator with Java Graphical Interface
I started working with the Swing framework, creating a calculator with the JOptionPane, and managed normally. Now I was launched the challenge of inserting buttons +, -, *, and / in the calculator,…
-
10
votes3
answers2338
viewsSplash Screen loading with application
My application, when starting, does the first search in the database. How I use the Hibernate, this first connection is a little more time consuming as it assembles the entire bank mapping. I’m…
-
9
votes1
answer510
viewsHow to make Jtable values the same as Arraylist<Pessoa>?
I have an example program that adds objects of my class type Pessoa in a JTable and also in a ArrayList<T>, this program has three basic functionalities which are as follows:: Add Alter Erase…
-
8
votes1
answer2380
viewsLeave program done in Swing with Windows appearance
I am developing application with Java Swing, but the screens are not looking windows window. Example of screen. I wanted to look like Windows even, with the title bar with minimize, maximize and…
-
8
votes2
answers1621
viewsDifference between AWT and Swing in component rendering
What are the main differences between the Swing and AWT interface construction libraries, regarding how to render the components of both and the performance?
-
8
votes1
answer808
viewsWhat is Event-Dispatching Thread (EDT) in graphical interfaces?
When learning to build graphical interfaces with swing/AWT, you hear a lot about the Event-Dispatching Thread (or EDT). Although I already have a certain coexistence with swing, I confess that I do…
-
8
votes1
answer176
viewsIs it possible to put 3 colors on a button?
I need to divide the button into 3 "equal pieces" and each piece has a different color. For example, a button with the colors Blue, Green and Red, each occupying 33.3% space. How to do this?…
-
8
votes1
answer1056
viewsTransfer focus from a Jtable cell right after typing time
Hello, I’m using a JTable for typing time card. I need help with this, but I’ve already done a search and nothing helped me very much. I’ve tried to do it in many ways and I couldn’t. I have several…
-
8
votes1
answer146
viewsHow do you create a "hidden" menu?
I have a Toolbar, and I want to make a settings bar on it. However, in order not to take up space, I would like it to be possible to hide/minimize it, something similar to teamviewer’s chat. My…
-
8
votes2
answers749
viewsHow to put icon on Joptionpane buttons?
How do I place an icon in the "Continue" and "Cancel" buttons that appear in the JOptionPane? The case is represented below: public void metodo(){ JPanel panel = new JPanel(); JLabel label = new…
-
7
votes1
answer525
viewsHow to determine if a point of a swing component is visible on the screen?
How do I determine if a certain point X within a swing component is visible on the user screen? For example, let’s assume that the JComponent To was added to a window B (normally, but not…
-
7
votes2
answers1998
viewsHow to close a Jframe using keyboard events?
I have a Jframe that I want to close when I press the Esc key... Well, I did that: public Cadastro() { addKeyListener(this); And then that: public void keyTyped(KeyEvent evt) { if(evt.getKeyCode()…
-
7
votes2
answers4016
viewsPays to migrate from Swing to Javafx?
Currently most of my applications are made with Swing. I’ve done 2 small projects web with JSF+Primefaces+Hibernate. My question is this:: It pays to quit Swing and study Javafx, or it’s better to…
-
7
votes2
answers2360
viewsFill Jcombobox with an object
I would like a help to fill one JComboBox with a class. In this class, return two parameters: Id and Desc. Category class I need to show in combo: private int Id_categoria; private String…
-
7
votes1
answer730
viewsClient-Server Chat application with Sockets does not work
I’m doing a project and I got to the communication part between the server and the client and I couldn’t get the output I wanted (image output). The goal is for the server and client to communicate…
-
7
votes1
answer604
viewsDifferences between listeners and Adapters in swing
When programming java graphical interfaces using swing, we always come across both types, mainly to assign and create events from button actions or other components. Though I’ve been messing around…
-
7
votes1
answer223
viewshow to center tabs of a Tabbedpane?
I have been doing some research, but I did not find it. I would like to know, how to center the tabs of a Tabbedpane. They always start from the left, but since they are only two tabs, I wanted them…
-
7
votes1
answer612
viewsHow to draw an arrow using Java2d?
I’m trying to draw an arrow inside a circle (similar to a clock pointer), but I’m not able to align the arrowhead with the rest of the line. I made the "arrow" based in this reply by Soen, but I’m…
-
6
votes2
answers8155
viewsPush button by hotkey in Java
I have a java application created by Netbean IDE 8.0. In this application I created a Jframe and put a Jbutton, which when pressed displays a message. private void…
-
6
votes2
answers437
viewsHow to access jTextField statico created with swing?
So guys I got one jTextField that works normally but when I put it as static the setText no longer works, and I need it static because I pass the same to a function, I did it without the swing and…
-
6
votes2
answers2098
viewsHow to close a Jdialog after you finish running a Thread?
I have a configuration window that opens on the first run of the application I’m developing. After typing the directories that the application will run the user click save, some tests are run and…
-
6
votes1
answer7351
viewsHow do I popular a Jtable?
I have a very simple java application, which connects to a database, in the console I type the query I want that is passed by parameter to the Query. Now I need to move all this to a graphical…
-
6
votes2
answers1295
viewsCustomization of Jtextfields
Many professional programs use Jtextfields or Jbuttons customized with different edges. Someone would have code examples to change the design of these buttons and text Fields to something like the…
-
6
votes2
answers30147
viewsJoptionpane, for example?
Well, Joptionpane needs all these complements: JOptionPane.showOptionDialog(parentComponent, message, title, optionType, messageType, icon, options, initialValue); Could you give an example of all…
-
6
votes1
answer156
views -
6
votes2
answers3795
viewsHow do I run a video inside Jframe?
I want to open a screen and contain a player to run the video that is attached to the project!
-
6
votes0
answers320
viewsAdd checkbox to a Jtree
I’ve looked around for plenty of examples JTreeIt’s checkboxes but it all seems very complex. Does anyone know a simple way, if there is one, to add to a JTree that I dragged to my frame, a checkbox…
-
6
votes1
answer2269
viewsWhat is the difference between setSize and setBounds?
What is the difference in Java Swing between methods setSize and setBounds?
-
6
votes1
answer103
viewsHow to create an application from a Maven file?
I was working with EJB and dealing with four simple Maven projects, a web project ,a desktop project (JSE Swing), a project (JSE) that had only the interface and ultimately a web project (which I…
-
6
votes1
answer570
viewsWhat is the difference between revalidate() and repaint()?
When working with swing, we usually call one of these methods after some change in screen components. But after all, what’s the difference between using repaint() or revalidate()? In what situation…
-
6
votes1
answer666
viewsPassing optional arguments in Java
I’m trying to learn how to run the class SwingWorker<T,V>, I’ve even done another question regarding one of its methods. Looking at the source code of this class, I found the method publish()…
-
6
votes1
answer481
viewsHow to "limit" a Jcombobox according to the selected item?
I have a JComboBox, and I limit the size of it, with the following code: jcb.setPreferredSize(new Dimension(100, 21)); However, I would like to know if there is a way that after I choose an option,…
-
6
votes2
answers207
viewsHow to apply Stylededitorkit to a Jtextpane without inheriting this class on my screen?
I have a problem with tabulation in JTextPane and I’m trying to reduce the default value assigned to it but it’s giving an error because I have to inherit two classes (one for the JFrame and the…
-
6
votes1
answer844
viewsHow to define the order in which components will receive focus through TAB?
To organize the component focus selection order up to version 1.4 of java, we used the method setNextFocusableComponent(). However, it was discontinued from the aforementioned version. I would like…
-
6
votes1
answer204
viewsHow to make the arrow rotate several times until it stops by itself after clicking the button?
In the question "How to rotate an arrow inside a circle using Java2d?", i managed to learn how to make the arrow rotate within the circle. Only I need to make the arrow rotate like a casino…
-
5
votes1
answer736
viewsJcombobox does not allow item change
I have a JComboBox which allows selecting only the first item clicked, in case I want to change selection it does not allow. In the jPanel There are two other combos that are identical with the one…
-
5
votes2
answers1540
viewsJtextarea receives the append but does not display the text
I’m having trouble using a Jtextarea. I need that every time something happens on my system, information is added in real time. However, he appears nothing. I’ve tried using the setText() and the…
-
5
votes1
answer793
viewsChanging size of Joptionpane.showInputMessage
I tried several methods like setPrefferedSize , setSize with/without pack() but nothing seems to affect Joptionpane code: selectProcess = new JOptionPane();…
-
5
votes1
answer2723
viewsHow to change the font color of a Jtextarea?
All over the internet I just found people wanting to know how to stylize part of the text and being "redirected" to JTextPane, then there are no answers to my question around. So there you go: I got…
-
5
votes2
answers639
viewsHow to get all paths of a Jtree?
How can I get all the paths of a JTree including the nodes which have parents other than root? root exemplo1 exemplo1.1 exemplo2 exemplo2.1 If I do something like that: for(int i = 0; i<…
-
5
votes1
answer493
viewsHow do I get an image of the computer inside a java application?
I have a registration and I would like the user to choose an image to represent it. Otherwise, a default image would appear. That is, in a certain part of the register would have a button that when…
-
5
votes1
answer1807
viewsShow textfield or textarea java
I can’t show words in textfield (or textarea) in my code, several hours in this and I still can’t. I got a link to the code. The most important lines are these, but if you want to test the whole…
-
5
votes1
answer1084
viewsRedirect System.out.println output to Jtextarea
I’m having trouble making this redirect, let’s explain. I own a class called Engine.java, this class is responsible for doing my processing and in it has all the System.out.prints process, the…