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

SetVisible(false) with the space occupied

I would hide a JButton in a JApplet. I'm using setVisible() method but I've a problem: it works but my GUI is shifted because of the absence of the component. Is there a way to hide a component and make its space occupied??? I know that is possible…
user2896152
  • 762
  • 1
  • 9
  • 32
1
vote
2 answers

JButtons aren't working?

For the game i'm making i made a button class to use for all the buttons in my menu. I finally managed to make my buttons appear on screen but now when i click them nothing happens. my button class: package menu; import java.awt.Image; import…
Lola
  • 179
  • 8
1
vote
2 answers

How to make a 'get' method for returning a JButton

Hello all I'm to return a particular JButton to then later setText on it. Here is a snippet of the code: JButton[][] tiles = new JButton[4][4]; for (int i=0; i<4; i++) { for (int j=0; j<4; j++){ tiles[i][j] = new JButton(); } } I…
Danny
  • 105
  • 1
  • 1
  • 9
1
vote
0 answers

Erase bufferedImage from JPanel by clicking a button on another JPanel

I'm just trying to open an image in one panel and click a button on another panel to make that image disappear. The following is just a very shorten version of the original code and addresses the specific problem. public class NahualProductionTest…
Marco
  • 35
  • 1
  • 7
1
vote
1 answer

Wait for Timer/Process to finish before continuing

I have a function that flashes the border of a JButton which gets called multiple times in a row. I want the processes to continue only after the entirety of the function completes. Right now, the flashing starts for one button, then it will start…
tbcrawford
  • 387
  • 1
  • 8
  • 23
1
vote
0 answers

JButton already selected when window loads - infinite loop

I have an array of JButtons which are displayed on a window when it is loaded up. For some reason, when the window loads, the first button seems to be already selected and so puts my programme into an infinite loop. I know that to stop this infinite…
ChatNoir
  • 415
  • 8
  • 18
1
vote
2 answers

Button background not changing

I am trying to make a reversi GUI and I am trying to change the buttons colors with an if loop. However, when it runs over this code it doesn't change the color: if(y.board[i][j - 1] == 2) { y.board[i][j] = 1; …
1
vote
2 answers

Java Graphics - draw shape on Jbutton

I am making a minimally small paint application for a class in Java. I need to make several buttons for the user to select different shapes, and on those buttons I am supposed to put an image of the shape they are using. For example, a button that…
Chris Campbell
  • 155
  • 2
  • 11
1
vote
1 answer

How to launch a second JFrame from clicking a JButton?

I'm making a To-Do List application and I have a PrimaryList frame and a SubList frame. When a user selects something from the PrimaryList (Grocery...or something like that) and then hits a forward arrow JButton, it is supposed to launch up the…
P_Drach
  • 121
  • 6
1
vote
1 answer

Create permanent hidden value of JButton whilst text on JButton changes

I have an array of 64 JButtons and want to give them all hidden values of co-ordiantes which must stay the same. The text on the JButton will change according to what co-ordinate is chosen. Is there a way to do this? This is my code for putting text…
ChatNoir
  • 415
  • 8
  • 18
1
vote
1 answer

Use array elements from another method

I have a questions about using array I have a method that creates JButton for a JPanel. I used JButton[] to store 7 buttons in it. The problem is those buttons must be setEnable(false) initially. they are only enabled when openButton is clicked. I…
Joe
  • 11
  • 4
1
vote
2 answers

Is it possible to call a different class when a Button is clicked

So I have a window with a JButton called "start". What I would like to happen is when that button is clicked it will run a separate class I have already created. Is this possible and if so how would I go about doing it? Thanks for all your…
Michael
  • 13
  • 1
  • 6
1
vote
2 answers

Java GUI BorderLayout application 4 buttons Left, right, up and down each move location

I have been breaking my head for days over a project I have to do in my Java beginner class about GUI BorderLayout Jbutton and I really hope some one here can help me out to understand it or shed some light. My task is to create a BorderLayout…
Elivan K.
  • 285
  • 1
  • 3
  • 13
1
vote
4 answers

Graphics text won't update until other operations are done

I have a JButton which performs an action when clicked. In the actionPerformed I want to update the button text before calling the NotifyObserver, which contains a big number of calculations. The problem is that the buttontext won't update until all…
JayJayPartay
  • 57
  • 1
  • 5
1
vote
4 answers

How can I update a JFrame faster than with repaint();

I'm trying to develope an menue with transparent buttons for a game. My problem was, that the buttons piled up with every time I hovered them. So I added an MouseListener which executes myJFrame.repaint(); every time I hover them. The problem is,…