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

Java: Creating multiple (duplicate) buttons that perform the same action but to themselves

BACKGROUND INFO: I want to make a 9x9 grid of buttons that act as empty beds. All buttons say "Add bed" and when clicked open up a window to write data about the occupant. Once saved the button will change to an occupied bed image. QUESTION: Is it…
Chris Collins
  • 89
  • 2
  • 11
1
vote
1 answer

I want to Enlarge my JButton Image when my mouse hovers over it

I can't figure this out for the life of me. What I want to happen is when my mouse hovers over the "Start" JButton in the menu to enlarge it by like 50-100px. What is a way to do that, that would work with my code here? thanks in advance! "I'm using…
BScody
  • 11
  • 2
1
vote
1 answer

actionEvent of dynamically generated JButton not working

I'm adding buttons dynamically. when i click that button, action should perform and i need values of which button got clicked. import java.awt.Component; import java.awt.Font; import javax.swing.*; import javax.swing.table.*; import…
user1742919
  • 401
  • 4
  • 11
1
vote
3 answers

When using null layout in Swing, my components don't appear until I hover on them

Recently I've been getting into making some simple games with Swing in Java. My current project is a chess-like game, so I figured I would start by making an 8 by 8 grid with JButtons and go from there. The problem is that every time I run my app,…
David Simka
  • 556
  • 1
  • 5
  • 14
1
vote
2 answers

Remove button after it has been clicked?

how would i get my program to work so that when a button is clicked it is removed? here is the code: //Mainmenu JFrame frame1 = new JFrame(); Container pane = frame1.getContentPane(); JButton a = new JButton(new…
runit
  • 45
  • 1
  • 4
1
vote
3 answers

Why is my simple JFrame displaying weird?

I am a newbie at Java Swing/AWT and I have this code following working for a simple PopUp dialog which closes on any of the JButtons beind clicked, but displays real wonky. Does anybody have suggestions on what and how to fix? import…
LambeauLeap
  • 285
  • 2
  • 4
  • 11
1
vote
1 answer

Rectangle Color Chooser program

I am having two problems here. I'm making a simple program to test, basically when you click the button JColorChooser will pop up and you can choose what color you want your rectangle to be. And the second problem is i cannot position my buttons at…
1
vote
1 answer

Is there a way to set the Ubuntu default focus button color in Swing?

I am just trying to have some of my JButtons to be painted fully orange in addition to the orange border when they have focus. Instead, setFocusPainted(true) turns out to only paint the border: Many applications seem to use the full orange buttons…
ChrisK
  • 158
  • 1
  • 13
1
vote
0 answers

Multiple JButtons, need to change the text of the button when it is clicked

Here is the problem, I have 26 JButton components, from which I have to select 8 at random and place them in a 2 x 2 grid in two JPanel components. When a button is clicked, I need to replace it with another random button selected from the original…
jarid.wade
  • 19
  • 6
1
vote
1 answer

JButton toggle method not working as expected

Here's what I'm trying to do: Create a JButton, and when clicked, its setText() will change to Happy, and then when clicked again, its setText() will change to Sad. Basically, I want it to toggle between Happy and Sad when clicked. (Sorry for the…
Nick
  • 61
  • 8
1
vote
3 answers

JButton ActionListener not responding

I couldn't find the answer anywhere else online, so I came here. I apologize in advance if the mistake in my code is very obvious; I'm still quite new to java swing. Here's what's going on: I have created a JButton named toggleElevators, and I want…
Nick
  • 61
  • 8
1
vote
2 answers

Netbeans: Update textfield on button event

I am attempting to make a basic character creation planner in netbeans as an attempt to learn Java so forgive me if my question is a bit silly. I have created the a text field that needs to be updated with a formula each time the relevant stat is…
NotJames
  • 13
  • 3
1
vote
1 answer

Buttons and paint method

I'm having trouble with my buttons. I know they're working because I've tested them out by exiting the problem through System.exit. Here is what my output looks like: https://i.stack.imgur.com/PKyDq.jpg When I click the close button, the handle on…
1
vote
1 answer

Why does my ActionListener only work for one of my buttons?

This is my code: import java.io.*; import javax.swing.*; import java.awt.event.* ; class plugin extends JFrame implements ActionListener { JPanel pnl = new JPanel(); public static void main(String args[]) { plugin gui = new…
1
vote
1 answer

Placing a restart button on my screen

I have created a "Game Over!" page when the user loses in my game. Under g.drawString(...), I am trying to create a button that the user can click to restart the game. I am having trouble getting a button to appear and stay visible. How can I…
TheAnonymous010
  • 725
  • 7
  • 19