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
-
2
votes1
answer909
viewsI can’t do a click counter on a Jbutton
I am developing a "game" where there is a button on the screen and the player has to click several times on the button to make money. For that, I’m doing a sort of click counter, where the variable…
-
2
votes2
answers451
viewsHow do I change the increment of a button by another button?
I have a button that adds a variable: x + 1, and every time I click on that button, the variable will increase 1 unit. But how do I program a button to change the function of button 1, so instead of…
-
2
votes1
answer244
viewsError trying to swap Jframe icon
I am using Netbeans, but I want to change the default icon of my application. But, I came across this error. Follows the code: import java.awt.Toolkit; /** * * @author renato.lazaro */ public class…
-
2
votes1
answer1100
viewsPick up Jtable’s line after Filtering Data
I’m wearing a TableModel(not the DefaultTableModel) which I populate with data from banco (MySQL), I also use a Class to filter through what I type into a JTextField. It is working correctly, but I…
-
2
votes1
answer99
viewsWhy is it that when I change the size of the window, the components are gone?
I built an application using windowbuilder eclipse. In it, when clicking with the mouse, a picture is drawn according to the last selected button. However, when I change the window size, all the…
-
2
votes1
answer448
viewsInitial focus on the Joptionpane OK button
I got the following JOptionPane: As you can see the focus is on the Cancel maestro option I need this focus to be on OK, but I have no idea how to do that. My code: JPanel panel = new JPanel();…
-
2
votes1
answer564
viewsAutowired spring boot in Jframe
In the development of a Spring Boot application for Desktop, it is possible to inject a @Repository in a class JFrame? If yes how? Some alternative? Code examples: @Repository public interface…
-
2
votes2
answers502
viewsWhen to validate fields from a swing form?
I was wondering if someone could help me with the validation of forms fields in java desktop. When should I perform validations, in the field (focusLost) output or in Keystroke(keyPressed), or other…
-
2
votes1
answer250
viewsApply Syntheticablackeyelookandfeel to the application
I would like to know how I can apply new look and Feels that are not part of JDK. In trying to apply, is giving an error in which I did not find an answer that could solve the problem. For example:…
-
2
votes1
answer91
viewsSlow opening of Jframe with Hibernate
Good morning to all. I have a Swing application that has a Jframe using Hibernate 3 for networked Mysql BD persistence. When I run through Netbeans, it opens very fast. But when I run the jar built…
-
2
votes1
answer909
viewsHow to close one screen after opening another?
I’m having trouble closing screen, I’m programming in eclipse. When running, the program opens and the Login window appears, when the user enters the correct code and password, a message appears to…
-
2
votes1
answer263
viewsResize TAB spacing in Jtextpane
I want to change the tab key of jTextPane because it has many spaces, for example: It is currently found like this: Uma casa azul // após TAB Uma casa azul And what I want would be like this : Uma…
-
2
votes1
answer150
viewsHow to create Tablecellrenderer for strings?
I wanted to know how to make a Tablecellrenderer for strings. on this topic here: How to use a selection setBackground in custom Renderer? I saw that the guy had to "values". I wanted to know if to…
-
2
votes1
answer504
viewsHow to make this relief by hovering your mouse on a Jlabel?
The board is 500x500 and each square of it is 50px, so the variables NovaPosicaoX and Y always take the edge of the square where ta the mouse pointer. The problem is that the relief only works on…
-
2
votes0
answers81
viewsLoading Jtable and processor gets high in process
I’m making a sisteminha and in it has a JTable and I need to loader my data, I’ve been analyzing by task manager that when this table load function is called, it greatly increases the processor…
-
2
votes0
answers895
viewsJava Swing program does not open window outside of Netbeans, but is open in processes
My problem is that I made a program in Java in Netbeans and it works normally, but the problem is, when I open it. jar outside the IDE, window is not opened. Here a simple code with the same…
-
2
votes1
answer169
viewsDoubt with Jcombobox to insert data at runtime
I’m new to Swing and this is the first Java application I’m actually doing, but I’m having doubts about Jcombobox, because I would like to make a field (Jtextfield) where I put the directory and…
-
2
votes1
answer160
viewsTreat empty field even containing spaces
I made a Celsius temperature converter for Fahrenheit, I’m willing to treat if in JTextField is different from 0, display the temperature in Fahrenheit, but appears 0.0 until empty, with spaces…
-
2
votes2
answers700
viewsHow to disable a java button without removing its color
I have a button that when you click it changes color, but if you click it again nothing should happen. However, I still can’t block this action. I tried that code: private void…
-
2
votes1
answer220
viewsHow to change Graphics2d objects off paintComponent
I wonder how to change the color of a drawRectangle() of Graphics2d java, out of the way @Override paintComponent(). It turns out that this change should be temporary, only when the mouse pointer…
-
2
votes1
answer1282
viewsChange label color according to screen state
I’m having trouble changing the color of a label’s content according to the state of my screen (enabled/disabled). I wonder how I do so I can make him change the color. I made a very simple example…
-
2
votes1
answer1039
viewsSeparate address path from string
On my application JAVA, on a screen, I have fields referring to the address, I have two means of registering this address, I can pick up automatically searching for the zip code most of the…
-
2
votes1
answer1049
viewsPositioning components within a Jframe
I’m trying to position some components on a screen, but it’s not working very well. So I created a kind of simple example to illustrate the problem. I accept subjects to perfect the way I’m doing…
-
2
votes1
answer455
viewsModifying a Jslider
I’d like to do two things: first: add a label, or anything, that allows me to put a "text" below the colors. Example in illustration: 2nd: Make the pointer/indicator of the slider, go to the color…
-
2
votes2
answers1175
viewsHow to position the cursor at the beginning of the field?
How can I make a component (JTextField, JFormattedTextField and others) when being clicked/gaining focus, position the cursor in the position 0 component, especially when the component is already…
-
2
votes1
answer264
viewsError adding placeholder to a text component
I am implementing the component of this topic together with the following instruction: PromptSupport.setPrompt("Digite..", field); This command is from biblioteca swingx-core-1.6.2 and adds a sort…
-
2
votes1
answer187
viewsHow to move animation in a clockwise direction?
Good guys, I’m developing a little project that aims to simulate the controlled environment of train tracks, where I have 3 trains circulating in a clockwise direction, where the three pass by the…
-
2
votes2
answers804
viewsFormat Jlabel text with different colors
How could I format with different "properties" a JLabel and its content? For example, I wish I could set a color for my text JLabel, and another to string that this concatenated with it. It is…
-
2
votes1
answer374
viewsHow to change the background of a Jdatechooser?
I have a JDateChooser and I’d like to change the background when he wins focu, but I’m not getting it. I tried to do some ways: dataChooser.getDateEditor().getUiComponent().setBackground(new…
-
2
votes0
answers40
viewsJformattedtextfield deleting entered data
I have 4 Textfields to put DDD, numbers before the hyphen, numbers after the hyphen and zip. private JTextField ddd=null; private JTextField antesh=null; private JTextField depoish=null; And a…
-
2
votes2
answers161
viewsPosition Buttons Scaled Table Using Layouts Manager
I’m having trouble positioning components. I have a table, and 3 buttons, and I’m trying to place the buttons above the table centrally. Example: I tried to use the FlowLayout, and the result was…
-
2
votes1
answer331
viewsHow to know if a Jdialog window is open or closed?
I was wondering, how can I know if a screen, in my case a JDialog is open. Is there any event or way to know this? Note: I will use this "information" as a parameter in a condition, for example, if…
-
2
votes1
answer395
viewsHow to validate a text field with Inputverifier?
Usually when I need to validate a text field without using action events, I use focus events such as those available from the interface FocusListener. In this example, I check if the field was…
-
2
votes1
answer499
viewsHow do I define the size and place of components?
I created this code in java to train a little and learn but I can not set the place where the JComboBox and the JTextField will appear and the size of them as I do? I want to leave them in the…
-
2
votes1
answer102
viewsArrows do not move in text field with regex
I have the following code with a regular expression inside a method Keyreleased, which allows only some characters to be typed by the user in a text field: String text = input.getText(); text =…
-
2
votes1
answer155
viewsData is not displayed in the table by Abstracttablemodel
I am developing a ticket request system, but for having to add a JXDataPicker in the table, I had to implement the AbstractTableModel. The model apparently agrees with the documentation, I can…
-
2
votes1
answer261
viewsText file is not displayed completely in Jtextarea
I put it up to show you the packages, so you can tell me if I’m making proper use of the MVC If I save in txt: [Maria;32] ; [Joao;44] e [Luna,12]` he just shows me Nome: Maria Idade 32 and Nome…
-
2
votes1
answer88
views -
2
votes1
answer65
viewsProgram works by debugging but not running
I’m doing an old game and I’d like to know if the button pressed that I set in class MenuPrincipal is returning the correct value to the main class that controls the change between windows. Normally…
-
2
votes1
answer364
viewsArrange Boxes vertically
I wanted to put panels in specific positions, so I tried to combine some layout managers, but I still didn’t get the result I need. I tried to use the gridLayout, so the components wouldn’t be…
-
2
votes2
answers1331
viewsHow to change the vertical grid line size of a Jtable?
How do I change the size of the vertical grid lines of a Jtable? Ex: jTable.setRowHeight(30); This method above changes the line width. Have some other similar to this which changes the vertical…
-
2
votes1
answer64
viewsIllegalargumentexception when adding components to Jframe
I’m doing a project of the game Sokoban, and I got to the part where I created 2 Jbuttons to select the level. Now when I try to run a program, it’s a mistake. I created both buttons and action in a…
-
2
votes1
answer699
viewsGrab Id of an objects in the combobox
In a Frame for registration of cars, I have a combobox1 with the brands of cars and another combobox2 with the models, when I choose a brand in CB1 only appear in CB2 the models related that brand.…
-
2
votes1
answer145
viewsJcombobox popup is visible until you click the arrow
I have a JComboBox populated with Jcheckbox’s working normally, but when I click on an item, the Jcombobox popup closes. To see if Jcheckbox has actually been marked, it is necessary to open again.…
-
2
votes2
answers1169
viewsException error in thread "AWT-Eventqueue-0" java.lang.Nullpointerexception
I’m doing a college project where I can register, change, delete and consult a product. In the query part, I try to search for the ID. Only this error happens and I am not able to solve. Exception…
-
1
votes4
answers1069
viewsSelect and drag Swing component
I made an application that draws rectangles, dots, straights, etc. I wanted when the user clicked with the mouse on top of a drawn polygon, selected the polygon and dragged to where he wants on the…
-
1
votes1
answer674
viewsHow do I get the name of a button in Mouselistener?
How do I get the name of a button in a class that implements Mouselistener: public class Viewer extends javax.swing.JFrame{ public Viewer() { initComponents(); } public void init(){ MouseListener…
-
1
votes1
answer2615
viewsAdjust Image Size with Java Imagery
I would like to resize an image to be shown in my jLabel. Here’s my code: BufferedImage imagem; Icon novaImg; try { String newPath = "file:///" + aleat(); // carrega imagem aleatória imagem =…
-
1
votes1
answer380
viewsDraw a line on Jlabel and Jpanel
I am finishing an old game, and I would like when someone wins the game, a line was drawn on the line, column or diagonal, in which the game was completed. I’ll post my code below: This is the game…
-
1
votes2
answers1435
viewsDoubt about Listener for Jcombobox
Someone would know to tell me some listener for when I select an item in Jcombobox it gives me a warning for example. Remembering that when I open my component(Jframe) I select items inside by the…