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
2 answers

Swing - positioning some JButtons

I'm trying to make a little game with JButton objects. My problem is, when I add buttons to my panel, they don't position where I need them. To be more clear. This is the Image I have : Here's my code : My main class which extends JFrame adds a…
pred
  • 185
  • 1
  • 14
1
vote
1 answer

How to make JButton reference object when pressed?

First off, this is my first post to Stack Overflow so please forgive me if I am not following some of the proper etiquitte. Im trying to make a GUI program that will display different food genres and then when the user presses the genre they want it…
Butters573
  • 37
  • 1
  • 5
1
vote
1 answer

Disable a jButton Conditionally

I have a jTable that containing some accounts data. I want to disable a button when i click on jTable Row, if the cell text(Data) is "NO" of column number 4 (in code vise column 3). Below is my code, but it does not work. int selectedRow =…
Mahesh
  • 109
  • 1
  • 2
  • 12
1
vote
1 answer

How to work with Swing timer

I'm trying to stop the program for a second using Swing Timer. Timer timer = new Timer(10000, new ActionListener(public void actionPerformed(ActionEvent e) {})); didn't work public class Card extends JButton implements ActionListener { int…
ForJava
  • 13
  • 2
1
vote
1 answer

Java jbutton not visible

I have created a jbutton in the correct way (I'm assuming), and have added it to the jFrame, is there any reason why I am unable to see my button when I run it? import javax.swing.*; import java.awt.*; public class MainMenu{ public JFrame…
ThomasMcDonald
  • 293
  • 3
  • 7
  • 18
1
vote
1 answer

multiple JButton actionlistener from another class

hi everyone i have a problem on how to create a separate class of actionlistener this is my code right now which works fine but doesn't fill my needs. for (int x = 0; x < buttons.length; x++) { buttons[x] = new JButton(name[x]); …
1
vote
1 answer

Java Swing - JButton wrong border

I try to set new red border to my "Ok" button, but instead of I get from this. How to make 1-st picture? (it's photoshop) I try button.setBorder(new LineBorder(Color.RED, 1));
Denis
  • 503
  • 8
  • 32
1
vote
2 answers

make jbutton to turn on and off

My goal is creating a function that waits half second, set the jbutton's background to red for one second, and after this second the jbutton will return to normal. Cant make this work.. This is my Function private void paint(final int num){ …
Erez
  • 502
  • 3
  • 6
  • 17
1
vote
1 answer

JTextField - Moving cursor using a button

I'm really struggling to find the functionality (if it even exists), to move a JTextFields cursor by clicking a Button, instead of using the mouse. For instance, I have my text field with a string added. By clicking a back button, the cursor will…
JoshuaTree
  • 1,211
  • 14
  • 19
1
vote
1 answer

JButtons, ActionListener, and JOptionPane

I'm trying to give a popup JOptionPane MessageDialog if the required items are ticked or not ticked but I don't get anything. Basically I'm checking which button is pressed using the action listener and then check which user was selected in the…
Juan
  • 198
  • 1
  • 14
1
vote
2 answers

Enable one JButton and disable another

There are two buttons in my ui which re-directs to two JFrames. I am trying to make that if user press button one, button two becomes disabled, and if the user presses button two, button one becomes disabled, so that the user cannot open both the…
Rudy dev
  • 47
  • 7
1
vote
3 answers

Auto Click to particular tab when button is clicked in java

I have a JTabbedPane with 5 tabs in it. I also got 3 other buttons in same JFrame where my JTabbedPane is added. I want to make the user able move to particular tab when a particular button is clicked. Here is the image example Now for example if…
user4099884
1
vote
4 answers

Setting Background of a Jbutton

I have 5 JButtons: b1, b2, b3, b4, b5. By default, their color is gray. When I click on any button, the background of that button changes to white. When I click another button, I want that previous clicked button to change its background to gray,…
mithun1538
  • 1,447
  • 8
  • 25
  • 32
1
vote
1 answer

Opening a new JFrame using a JButton

I have two classes (Sampling and Stacker). The Sampling class (my Main class) is extends JFrame and has a JButton with an ActionListener to open the Stacker class. The problem is when the button is clicked, the Stacker class will open but only a…
ZeroCool
  • 437
  • 1
  • 7
  • 23
1
vote
1 answer

Changing the color of a jButton every couple of seconds

I'm trying to create a little button game for a school project. What the game is, is there are a couple buttons that every like 3 seconds will flash a color then if you press it when the color is up, it stays that color. I have all the buttons…
Jonah
  • 1,013
  • 15
  • 25
1 2 3
99
100