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

Add new label and textfield on button click Java

I have this code with three buttons. I want to add a label and a textfield after a buttonclick. So for the 'button' I want to add the 'label' and 'textfield. For 'button2' I want to add 'label2' and 'textfield2'. And so on. I already have this…
Tyrion
  • 29
  • 1
  • 3
  • 8
1
vote
2 answers

How to start and stop a threads in netbeans from a jButton click

I write Java desktop app to fetch and post some data from my online rails backend app. The App have to call a get request every 5 second to update the relay state(example Arduino). here is my code: public class GUI extends javax.swing.JFrame…
1
vote
1 answer

Accessing changes made inside JButton ActionListener outside the ActionListener

I ll explain my code in a bit: I have a JComboBox with a list of items And when the JButton "Select" is pressed, it registers the last index of the last selected item from JComboBox. Now I need to access this index inside the main. Here is my code…
newbie2015
  • 581
  • 5
  • 29
1
vote
2 answers

How to add a jbutton to a jpanel

I've trying (unsuccessfully) to add loop generated JButtons to a JPanel. The thing is that the JPanel is over JScrollPane. Here is my code: String categoria = this.cmbCategoria.getSelectedItem().toString(); String[] partidos =…
Andrés Buitrago
  • 205
  • 1
  • 2
  • 9
1
vote
2 answers

java swing - how to change window background

I was trying to make a button that switches the window background from default to red. I haven't found any preset colors to match the default so i tried to get it from panel.getBackground when i created it. I have an error at line 11, i don't know…
T4l0n
  • 595
  • 1
  • 8
  • 25
1
vote
0 answers

how to make a option pane with 3 button that have that have its own function

I want to make a miniLayar is shown as option pane with one of the button functioning like tmbATM. Is that possible :( I'm desperate how to do it. and each time that button is pressed, the i value is +1. can anyone figure this out ? public void…
DovahVinn
  • 15
  • 4
1
vote
2 answers

How do i get rid of a blue border surrounding my button? For Java GUI

Because it wont let me add an image - new account This is utilizing the Java GUI The above image is an image pasted onto a button, I've tried to make the button transparent so that the user can't see it but I can't seem to get rid of this blue…
user3610386
  • 109
  • 11
1
vote
3 answers

Add dynamic buttons to jpanel in Java

I'm trying to do a program in Java that will make a button appears in a JPanel where and when it's clicked. To do that, I have the method run, with the following code: public void run(){ panel.addMouseListener(new MouseAdapter() { …
CodeSniffer
  • 83
  • 1
  • 10
1
vote
1 answer

A method that returns the object last in focus?

so I have a couple JButtons, and hundreds of JTextFields throughout a program (with CardLayout, don't worry). I want these JButtons to find the JTextField that was last in focus, so when the button is clicked, it sets the text of that field to be…
user4728253
1
vote
1 answer

JButton and GUI freezes after click

When Eclipse compiles this code everything works fine except the GUI freezes after the user clicks the "add" button. The answer is displayed and the work is shown. Can anyone shine some light on this problem and maybe give me some advice for the…
Michael Collins
  • 380
  • 1
  • 4
  • 19
1
vote
1 answer

2D Array of JButtons not getting clientProperty right

Introduction I am trying to create a cheeckers game in which I initialize an 8x8 array, fill it with white and black buttons to create the game table then I fill in the 1,2 || 5,6 row with white and black pawns with a loop, in which I name them, as…
1
vote
3 answers

Switch between multiple JFrames

I'm relatively new to Java and I'm trying to make some kind of quiz. I created 3 JFrames, all in the same package. On my main frame, there are two buttons (one for the english version and the other one for the german version). I want to switch…
Vivi Huber
  • 11
  • 1
  • 1
  • 2
1
vote
1 answer

Cardlayout With Jbutton Not Switching

Hello I am fairly new to java programming and I am currently trying to work on a small game with a GUI, Right now I am stuck at an issue where I can only use a normal button with a card layout, unfortunately I want to use my own icon with the button…
1
vote
2 answers

Java GUI - JButton opens another frame from another class

i'm having trouble to get the 2nd frame to display the GUI Components. i've opened the frame using the JButton from the 1st frame. Here's the screen shot This is the first frame - ClientModule.java 2nd frame - ClientMenu.java Here's the codes i've…
Preeyah
  • 363
  • 3
  • 16
  • 42
1
vote
1 answer

How to "Unclick" a JButton without releasing the left mouse button?

I have set up a mouse dragged listener. I trying to set it up where you can click one button then drag your mouse over others to click the other ones. The problem I am having is when you click the first button it turns grey like its waiting for you…