Questions tagged [jbutton]

A JButton is a common button in Java Swing.

A JButton is a common button in Java Swing that allows users to execute actions and events which have been tied to that button. It is designed to be used with ActionListener and Action classes for interacting with a gui.

Relevant Java Tutorials:

4918 questions
1
vote
1 answer

ActionListener code triggered twice

I made jbutton and added ActionListner to it but the code in public void actionPerformed(ActionEvent e){} exectues twice.It prints test twice,instead of just once.Here is my code JButton testbut=new JButton("Test"); ListenForButton2 l=new…
1
vote
1 answer

Resizing JButton causes it to disappear

I want all of my buttons to be the same size. The one with text "Open Save" is the widest, so I want to use that one as the metric for resizing the other buttons. However, when I have this line of code in the program, the button won't display:…
failure
  • 215
  • 1
  • 3
  • 12
1
vote
1 answer

Change position of JBouton dynamically

In my JFrame, I have in each line two label and one JComboBox ordred as follow: Label JComboBox Label **Bouton** The user can add a new line with the same entities. So, I add a bouton and when user submit a new line is created. Label …
Mehdi
  • 2,160
  • 6
  • 36
  • 53
1
vote
5 answers

Why aren't the JButtons displayed on the JFrame?

When I run the program the window and all it's properties are right, but the buttons won't show up, any idea of what I've done wrong? I have two classes window and TimeTable0: Here's window: package timetable0; import…
user4450842
1
vote
2 answers

Grid layout not working?

I am trying to make a 2x2 grid layout that has a JLabel on the top left, and three buttons on the other three spaces. When I do this, I get the unexpected result of one big button (filling up the entire JDialog) that says "Do you want to push me". I…
user5241092
1
vote
2 answers

JButton doesn't work at all after i dispose existing frame and sets the new frame(re instantiate another frame)

I made a calculator and to increase its functionality and simplicity i made three frames which support simple , scientific and conversion calculator calculator works perfect till i use it once but when i change my calculator type from simple to…
user5224964
1
vote
3 answers

Update JLabel integer value using Jbutton

I have a JLabel and a JButton named increment. I want to increment JLabel value everytime I click JButton value. When using this code, the JLabel value changes to 1 only once and then nothing happens for extra click on the JButton. Any Kind of help…
1
vote
2 answers

Button remains focused after clicking

I'm getting some trouble with a toolbar I made. In this I have 4 JButtons and below a JTable, which is set on focus when my windows shows in order to see the JButtons unfilled. This is how I set each JButton: btn = new JButton("New"); …
Matteo
  • 11
  • 5
1
vote
1 answer

Adding Ok/Cancel buttons to existing JFrame

I have a method which is popping up a JFrame/JScrollPane which has 2 columns, one for the keys of a hashmap and another column for the values of the hashmap. The values populate in editable text fields. I am trying to add an ok and cancel button to…
GregH
  • 5,125
  • 8
  • 55
  • 109
1
vote
2 answers

Change button text after click, then revert the changes after clicking again using JAVA ActionEvent

I am displaying the code that I wrote for changing the text when a button is clicked. Now I am trying to get the default text by clicking the button again, but unable to do so. Please advice. import javax.swing.*; import java.awt.event.*; public…
Mudit
  • 11
  • 1
  • 2
1
vote
0 answers

JButton inside JMenuBar isn't tight-fitting

Take a look at this picture: It seems my green arrow button keeps making the JMenuBar taller than it should be, notice the space above and below the rest of the buttons. How do I stop it from doing this? I've tried making the JButton border/padding…
danglingPointer
  • 882
  • 8
  • 32
1
vote
2 answers

Creating dynamic button arrays

I have a loop to create buttons like so. These buttons act as beds in a room (the room is an InternalFrame). addButtons is a JButton array. for (int i = 0; i < addButtons.length; i++) { addButtons[i] = new JButton(" Add Bed "); //…
Chris Collins
  • 89
  • 2
  • 11
1
vote
1 answer

Java swing ActionEvent for button click

@HoverCraftFullOfEels helped to create this code, what would be the best way to add a button that selects all of the ellipses and changes their color from INACTIVE_COLOR to ACTIVE_COLOR. My approach was to add another button to the button panel and…
feltersnach
  • 406
  • 3
  • 20
1
vote
1 answer

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table

I am rendering an JButton with an image on it basically to simulate JCheckBox behavior. Why don't I just let the JTable to render JCheckbox? Simply because I need bigger checkboxes and there's no way I can resize them (as far as I know). So, I have…
1
vote
1 answer

Extending a java class whilst also altering it

I've been a lurker on stackoverflow for some time. I'm teaching myself Java, so bear with me if this is a rather elementary question (I couldn't find the answer on here though). If I have a java class (like the one below), which I wish to use in…
Pineapple
  • 91
  • 7