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

JButton not shown on screen

Im trying to make an application that will change the state of a traffic light in the click of a button. My code: Main import javax.swing.*; public class PP416 { public static void main(String[] args) { JFrame frame = new…
God
  • 1,238
  • 2
  • 18
  • 45
1
vote
1 answer

Java Blink JButton during 2 seconds

I want the program to wait 2 seconds while blinking the button. I have this code for the blinking button: import javax.swing.*; import java.awt.event.*; import java.awt.Color; public class a { static JFrame frame = new JFrame(); static…
alexandre1985
  • 1,056
  • 3
  • 13
  • 31
1
vote
2 answers

Assigning random value to JButton

I need to assign different number from 1 to 8 to JButton Array. But the elements of array has to be different. Random random = new Random(); JButton[] number =…
Ms. Sahin
  • 25
  • 4
1
vote
1 answer

how to get rid of visual effect when disabling buttons in java

When I'm setting the button to be disabled using this: jButton.setEnabled(false); then there is this visual effect visible on the second element -> How can I disable the button, but keep the the look of the first element?
redCodeAlert
  • 603
  • 2
  • 7
  • 18
1
vote
2 answers

Calling a Java AbstractAction from a button/mouse release

In a simple calculator app, I use abstract actions to handle the buttons being clicked with the mouse and the respective number pad keys (with key bindings) being pressed. I wanted certain cosmetic changes to occur upon using the keyboard, such as…
KiloJKilo
  • 465
  • 1
  • 6
  • 16
1
vote
0 answers

How to move an Object from one JButton to another?

Basically, I've created a board filled with boardFields extending Jbuttons, implementing ActionListeners. After adding a "Unit" to a boardField, I cannot figure out a method to move it to another boardField. Here's the code. import…
1
vote
1 answer

BorderLayout Left Assignment

I have a JPanel with BorderLayout and some Buttons on SOUTH. When I add the Buttons they are in the middle. But I want them to be on the left. Is that possible?
vivanco
  • 13
  • 2
1
vote
3 answers

Add JButton to JPanel from Different Class

Hi is there a way to Add JButton to JPanel from Different Class. So basically the JPanel is in a Class A and JButton is in a Class B how can I put the button on the Panel which is in a different class. Hopefully this makes sense if you need me to…
Navleen Singh
  • 155
  • 2
  • 11
1
vote
2 answers

Car buying program - need to calculate the final price with a JButton

I have values set for each of the car buying options but when I click the button I keep getting 0. I can't get fP to update after I declare it. Here is my code: public class CarOptions extends JFrame { //All the Buttons needed private…
mcguirjk
  • 41
  • 3
1
vote
1 answer

MouseEntered and MouseExited not working

I am having trouble with mouseExited and mouseEntered events. They are not executed. And I know it is because of the setLayout. If I comment it, the problem dissapears.This is my code : public class Test{ public static void main(String[] args)…
zaa
  • 79
  • 8
1
vote
2 answers

Money accumulator buttons

I'm building a project for school and I want to make three money buttons (quarter, nickel and dime) that accumulates their value with every click of the button. When I'm done the text displayed will be grabbed and reParsed back to a double. I have…
Shawn
  • 9
  • 2
  • 6
1
vote
1 answer

How to intercept paintComponent from Custom JButton

I created a Custom JButton with transparent background and a drawn line from graphics.drawRoundRect() but when I start my program for testing, my JCheckbox keeps appearing on top of the button. It looks like this at the beginning And this is after…
user4010555
1
vote
1 answer

InternalFrameListener for inter-frame Button pressing?

I need the frame to update and display how many times the Button has been pressed (the button's text to update) If I can use actionPreformed() to be locked on to specific events (Button press, or the Menu item being pressed), then I think that…
Eric Bub
  • 11
  • 1
1
vote
3 answers

Assign int to JButtons to make method more efficient?

I'm making a game with 9 JButtons that each do basically the same function. How can I make it so that these buttons each have an int (0-8) attached to them so I don't have to write the same method 9 times? Here is the method as it is…
user4258987
1
vote
2 answers

JFileChooser crashes - Java 7

I'm trying to make my program load a txt file with JFileChooser, but it doesn't seem to work. When I press the JButton, the console gives me a lot of errors. Here's the entire code so far: import java.awt.*; import java.awt.event.*; import…