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

How do I add JButton to JFrame?

At the moment this program displays a frame with a circle in its center. I tried to add a JButton to the frame so I could implement an action listener later to display the circle when pressed, but right now I'm having trouble actually showing the…
Ryan Hardin
  • 81
  • 2
  • 3
  • 12
1
vote
1 answer

Why can i only change button background color in the GUI constructor?

import java.awt.*; import javax.swing.*; import java.util.Timer; public class GUI extends JPanel { private static final long serialVersionUID = 1L; private static final int ROWS = 50; private static final int COLS = 30; public…
Carl5444
  • 25
  • 4
1
vote
2 answers

StackOverflowError when using getattr in Jython

I'm writing a text editor in Jython. This text editor has a toolbar which is displayed with a ToolbarView class and handled by a ToolbarController class. Some actions can't be dealt with by the ToolbarController on its own, so these are delegated to…
zapatilla
  • 1,711
  • 3
  • 22
  • 38
1
vote
1 answer

Write multipleline text into jButton in Netbeans IDE, java

In jButton,i want to write a title or text on button and it will look like Advance Search Option But the button text look like AdvanceSearchOption It won't take new line. I try change some properties but it won't work.
1
vote
0 answers

Changing Buttons From Different Panels

I need help figuring out how to change Button b2 in MyJPanel2. I cannot make any changes to MyJPanel2. p1 (the variable representing myJPanel1) needs to manipulate a button located in p2 (the variable representing myJPanel2). In order to do this,…
1
vote
3 answers

Center buttons on a container java

I have a project that requires me to create a simple GUI that has a jTextArea at the top, and JButtons added from 0 to 9. This is pretty simple to do, however the program requires me to center the 0 at the bottom. The below code accomplishes that,…
James
  • 11
  • 2
1
vote
1 answer

JScrollPane scroll on the top page when the submit button click

Is it possible in Java Netbeans for the jScrollPanel to scroll automatically return to te top when a submit button click? Any idea?
bloomindindin
  • 85
  • 1
  • 6
1
vote
0 answers

Java Dice Roller Project (JButton)

I have a project that accepts the number of die and the number of faces on each die from the user. It will roll the number of die the user wanted, display the face each die landed on, and show the total of all the die together. This is exactly what…
Jaydelay
  • 73
  • 1
  • 2
  • 9
1
vote
2 answers

Error accessing array of buttons in java

I created an array of buttons in java containing 9 buttons like this JButton []button = new JButton[9]; When I try to access any of them later like body.add(button[0]); or body.add(button[1]); it return the following error Exception in thread…
Inzimam Tariq IT
  • 6,548
  • 8
  • 42
  • 69
1
vote
0 answers

How to change the layout clicking button in jung

I am using an SpringLayout2 for my graphical visualization. I have added Jbutton in order to change the layout by clicking this button.How can do this? can i do with LayoutTransition?. Ive tried the following code. JButton layout1 = new…
Steffi Ma
  • 70
  • 9
1
vote
4 answers

Java how to assign id to button and retrieve them?

I'm getting stuck while building a forum like application which has a vote button. I have vote up and vote down button for each content which are automatically generated. I want this button to only display the up and down arrow but not any text or…
Kent Ong
  • 97
  • 1
  • 7
1
vote
2 answers

Adding an action listener to JButton

I'm a bit at a novice in Java, and I ran into an error trying to add an active listener to the button in my GUI. It's a fairly simple GUI, if not a bit messy. Right now, there's only a label, button, and text area. What I'm trying to do evantually,…
user5330423
1
vote
2 answers

Java Swing - isRollover() value in JButton model

I was testing the ButtonModel's behaviour and I came across a strange situation. The isRollover() method does not return the expected (according to me) value. Here is the sample code I've just created: import java.util.logging.Level; import…
radekEm
  • 4,617
  • 6
  • 32
  • 45
1
vote
2 answers

Change button color onclick without final modifier

Consider the following code, used to change the color of a button when it is clicked. import java.awt.Color; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JFrame; public class…
ᴜsᴇʀ
  • 1,109
  • 2
  • 9
  • 23
1
vote
1 answer

How do I see if a button with an imageIcon loaded has been pressed in java?

I have a program where I have a settings button. This button has an image icon which shows an image. Any tips on how I can preform an action when it is pressed. Here is that code JButton imageButton = new JButton(new…
Sam Liokumovich
  • 91
  • 1
  • 2
  • 6