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
-
0
votes1
answer514
viewsError accessing local variable in anonymous class
For some reason netbeans asks to transform the variable i in the end, but if so, I cannot edit it. Follow the error: Error: local variable i is accessed from Within Inner class; needs to be declared…
-
0
votes1
answer143
viewsArraylist giving error
I’m doing a little program with a database and I can’t seem to get my list to appear in one jtable. I created the method and at the time I call my method it error, someone can help me code this…
-
0
votes1
answer3397
viewshow to take a textField value and move to an int variable?
How do I get the value typed in a field of the type JTextField and move on to a variable, so I can do calculations later? I tried to use getText(), but the variables being int, do not receive the…
-
0
votes0
answers756
viewsSelect item in Jcombobox and return associated value in Jtextfield in JPA
I try several times in a Swing form to make sure that when selecting the option in Jcombobox the value of the item in the column of the same row appears in Jtextfield. Once I managed to do this…
-
0
votes1
answer503
viewsHow to add scrollbar to a Scrollpane?
I have a panel, and I will have enough fields and buttons on it. I thought to use a JScrollPane not to make the screen so big. However, I’m not able to add this scroll bar. As I add a scroll bar…
-
0
votes1
answer268
viewsClose screen through Jmenuitem
I’m doing a simple system of enrollment of students and teachers and wanted to, when interacting with a JMenuItem called get out of, the program closed. I did the whole algorithm, but this with that…
-
0
votes0
answers53
viewsIncrement equal amount of service
I have a table with the service code, service, quantity, value and total. When I add an ITEM 1 in the table for example, the data of this service will be added in the table. But in case I add this…
-
0
votes1
answer2116
viewsPopular Jcombobox with Strings and Ids brought from the database
I need a popular JComboBox with the data brought from a table in my Mysql Database, but I don’t know how to leave an item attached to the corresponding ID. Example: ID 1 refers to the ADM profile…
-
0
votes1
answer366
viewsHow to differentiate buttons within the same event?
I would like to know a method to differentiate a button that generated event, in my method that will treat the events. In the example below I add the same class that handles the events to 2 buttons,…
-
0
votes1
answer623
viewsAlign JPANEL button
I want to align a single button to the Jpanel, but I’m not succeeding, using the default layout. public class Test extends JFrame { private JButton btn; private JPanel painel; private JScrollPane…
-
0
votes1
answer279
viewsHow to add an event to an icon?
I wanted to make it possible to open a screen, perform any action and so by clicking on an icon. I wanted to put different formats, so I don’t use one JButton. Because when passing the image to him,…
-
0
votes1
answer1097
viewsSet selected Combobox item as clicked on jTable
I am trying to fill in the form fields as per the item clicked on jTable. Text fields are normally filled in, but the combobox remains at the selected default value. //método que preenche a comboBox…
-
0
votes1
answer481
viewsHow to manipulate the site of Jlabels by having a wallpaper?
I’m trying to make an app that has a wallpaper, but I can’t change the position JButton or JLabel. I can only do it if I don’t have a background. Follows my code: public class teste extends JFrame{…
-
0
votes1
answer76
viewsIndexoutofbounds when filling an Abstracttablemodel
I have a AbstractTableModel who owns a List filled by a method that searches the data in the database. The method that fills the List has two overloads: one without any parameter (that searches all…
-
0
votes1
answer573
viewsAdding Financial Balance with Jtable
I’m trying to develop a sales control program in Java, but I have a problem when it comes to scheduling Jtable’s balance. As you can see in the image below, the balance is being updated per line.…
-
0
votes0
answers86
viewsUltialize same component in Jtabbedpane
Before describing the problem itself, let me explain what I’m trying to do. I will need to use some buttons that will do basically the same thing, only the actions they will apply change from a tab…
-
0
votes1
answer234
viewsApply component focus
I have a component that is a JPanel containing two JTextFields, wanted to be able to apply borders and funds only for the JTextFields, without applying on the panel. I treat everything on the main…
-
0
votes1
answer939
viewsOpen Jinternalframe from another
I was learning to play with JDesktopPane in order to use in future projects because I find this function very interesting. I tried to call a JInternalFrame from one button inside another…
-
0
votes1
answer448
viewsHow to initialize a blank Jpanel?
I’m starting to work with the package swing and manipulation of events and I came up with an idea to test some program that would create rectangles of random sizes and colors. Code creation and…
-
0
votes1
answer658
viewsHow to order Jpanel in different positions?
Which Layout manager should I use to position the panels as in the illustrative image below. Edit: I have the Painelx Class, which I am in JFrame as position SOUTH, within that class I have 2 panels…
-
0
votes1
answer148
viewsCreate method that takes typed time
How can I create a method that takes the time typed in a field? It will take the contents of the field to save in the database. I use pojo and dao. I made a very short example, what I need to do is…
-
0
votes1
answer217
viewshow to position a Jtextfield’s Caret?
I have a JTextField where opening and closing of parentheses is optional. However, whenever the user opens and does not close a parenthesis, my program gives error, because I use this text field to…
-
0
votes1
answer742
viewsCreating component dynamically
I made a method whose goal is to add a number of checkboxes according to the value of a variable that I will receive. I wanted him to stay inside a scrollPane so he wouldn’t take up more space than…
-
0
votes1
answer1357
viewsPut access restricted login permission
I’m using a code that was already made by someone, I made some modifications regarding what I wanted. This code has 2 types of "Administrator and Employee" access that you would like when you login…
-
0
votes1
answer125
viewsProblem in identifying the turn in the Game of Old
I’m trying to implement the Game of Old in Java with Swing, but my counter that defines the moves, does not change, so always displays the same move: import java.awt.Color; import…
-
0
votes1
answer411
viewsDoubt concerning Jframe Dispose()
I am trying to check the login screen, to know if there is already the configuration file where the access information is set. If it doesn’t exist, it was supposed to give dispose on the login…
-
0
votes1
answer2017
viewsHow to break line automatically into a texo component?
I would like when it reaches the maximum number of letters/words on that line, to break automatically. When I put a pizza works smoothly: But when I put more than one pizza the text gets bigger than…
-
0
votes1
answer154
viewsPosition Jcombobox on the screen
I made a combo box, in netbeans by command, and I can’t change it from location (in frame), Bounts values change, but it doesn’t move. I’ve used all kinds of commands (setBounds, setpoint,…
-
0
votes1
answer1020
viewsCreating field with weight format with two decimal places and 3 houses before the comma
I’m trying to create a "weight" field, but I’m having some problems. The weight can vary from 2 to 3 decimal places before the point. For example, it could be 80.00 Kg or 100.00 Kg. However, the way…
-
0
votes1
answer207
viewsCreating Dynamic Jtextpane component
I had a problem with editing labels, that was solved by using the JTextPane. So, I thought of creating my own component of this type, so that I can pass values "dynamically", and writing a few…
-
0
votes1
answer65
viewsImage does not update
I’m making an application where I use a Jfilechooser to choose an image, I take this image and copy it to a network folder. After that it executes a method that shows this saved image in a Label,…
-
0
votes3
answers422
viewsAllow only integers in a Jtable column
Below I have a model of Jtable. There is only one editable column for number (seconds). How to validate to accept only integers, and in case the user enters anything else except integer, return…
-
0
votes1
answer369
viewsHow to know the size of Jframe in the constructor?
I need to adjust the image size to the space provided by jframe. Error: Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Width (0) and height (0) must be non-zero at…
-
0
votes1
answer1069
viewscatch and set value of a Jdatechooser
I created a JDateChooser own, so I can make more personalized changes to it later. The problem is, I realized, if I pick a date on it, it just gives me the current date. For example, if I choose…
-
0
votes1
answer563
viewsJtable currency format
I am making a Cellrender with currency format. I placed 13 columns in a jtable, one has the recipes (Salary, 13th salary, Overtime).. and other 12 with the months. each month the person will enter…
-
0
votes1
answer411
viewsHow to check if the fields are empty before adding to the arraylist?
I have a question: how could I check if the fields of my Jtextfields are empty before adding to the arraylist? as would be the validation in this part of code? Endereco enderecoPJ=new Endereco();…
-
0
votes1
answer431
viewsCheck if you have reached the last row of the table
I’m using this code to do a approved or flunked, but when he gets to the last line, he’s not checking if he’s on the last line and he doesn’t give me the result. I would like to know how to check if…
-
0
votes1
answer834
viewsHow to disable/enable buttons of a Jframe as an option coming from another Jframe?
Currently I have two buttons on one JFrame: one to save and the other to update. Another JFrame, I have to register and edit. When I click Sign Up, I want the Save to be turned on and update off,…
-
0
votes1
answer450
viewsJframe does not update until function of button finish
When I click the button it calls a method, and until this method finishes the Jframe does not update the program is in the image below private void…
-
0
votes1
answer398
viewsIdentify selection of Jradiobutton
I created a code in java with 2 Jradiobuttons and need it to appear on the console which radio is selected, and when change radio, appear on the console as well. I’ve tried using the…
-
0
votes1
answer121
viewsPositioning
I’m having a hard time adding Abels in different positions, relative to a field (JTextField). I’d like to put one label before the field, the left, and a second label under the JTextField. Example:…
-
0
votes1
answer3390
viewsHow to change the color of a button?
I’m doing some experiments to get to know the Netbeans IDE better and I got this one button coloring question. Right-clicking on any jButton and selecting Properties, configure the item background…
-
0
votes1
answer365
viewsPopular combobox inside jtable with database, how to proceed?
Currently I populate a normal combobox this way: this.CadperfilLinha.removeAllItems(); try { Class.forName(Auxiliar.AcessoBanco.getDriver()); Connection con =…
-
0
votes1
answer673
viewsDynamically define text to Jlabels according to text field validation
I tried to add one label for each required component of my screen that is empty (field 01 and field 02), so I created a list of labels with the corresponding amount of fields/components. However,…
-
0
votes0
answers50
viewsWhy does Jframe have different sizes between window mode and full screen mode?
Well, I was doing the setLocation so that the Graphics are compatible with any game resolution. Then I realized a certain problem when I tried to make a frame.getHeight - figura.getHeight (The…
-
0
votes1
answer99
viewsError while trying to implement Jtextarea in Jtable
I’m trying to use this JTextArea in some columns of mine JTable, but something’s going wrong. I know it’s wrong, but I’m using DefaultTableModel. public class TextAreaCellRenderer extends JTextArea…
-
0
votes1
answer216
views -
0
votes0
answers60
viewsDate Validation using Jdatechooser
I’m trying to validate two dates in the following case: I created a Jframe that receives two data fields using Jdatechooser, as shown below: First field the user informs the shutdown date, second…
-
0
votes1
answer61
viewsAccess Jlabels without using switch case...
I’m developing a game with JLabel from 1 to 50, I can access them online without having to use a switch. You can verify that what changes in the code and only the lblBoard1 or lblBoard2 and so on,…
-
0
votes0
answers87
viewsPopular Jtable with BD data without using Defaulttablemodel
I’m doing a whole layered project and I read somewhere that the use of Defaulttablemodel is not very recommended. I am trying to receive values registered in the BD and fill a jTable with these…