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
8
votes
4 answers

Disabling space bar triggering click for JButton

JButtons consider pressing the space bar to be the same as clicking on the JButton (assuming the JButton has the focus, which I am assuming here). Is there a way to turn off this behavior so they ignore pressing the space bar? Also, more generally,…
Paul Reiners
  • 8,576
  • 33
  • 117
  • 202
8
votes
6 answers

Create an inspecting properties window, button driven as a JDialog

What I asked originally didn't clearly state my question/problem, so I will explain it better. I have a JButton that sets a JDialog to visible. The JDialog has a WindowListener that sets it to NOT visible on the windowDeactivated() event, which is…
Brian
  • 81
  • 3
8
votes
7 answers

Showing/hiding a JPopupMenu from a JButton; FocusListener not working?

I needed a JButton with an attached dropdown style menu. So I took a JPopupMenu and attached it to the JButton in the way you can see in the code below. What it needs to do is this: show the popup when clicked hide it if clicked a second time hide…
Joanis
  • 1,669
  • 3
  • 20
  • 32
8
votes
1 answer

Making button in JList clickable

I can't believe this does not work. I have a JList. I have set its renderer as follows. Basically RankingPanel is a JPanel with two labels and a button. topAchieverList = new JList(); topAchieverList.setCellRenderer(new…
codeNinja
  • 1,442
  • 3
  • 25
  • 61
8
votes
3 answers

Button ActionListener

Ok, so I made a simple program that adds the value to counter each time a button is clicked. Now, I would like to add "Auto" button feature to increase the value of the counter when the "Auto" button is clicked. I'm having problems with it because…
dev-cyprium
  • 758
  • 2
  • 8
  • 25
8
votes
4 answers

Auto-focus on a jButton on a jpanel

I have a JPanel loaded on a JFrame. The JPanel contains 4 JButtons. The thing I am trying to do is to get the focus automatically on the 1st jbutton so that I can traverse between the JButtons with the keyboard. I tried the…
Nitesh Verma
  • 1,795
  • 4
  • 27
  • 46
8
votes
5 answers

Creating JButton with customized look

I am pretty new to java swing and not familiar with paint(). I want to create a button in java swing with above look. Can anyone help me to do this. Any guidance would be grateful. Thanks in advance
Nikhil
  • 2,857
  • 9
  • 34
  • 58
8
votes
1 answer

Why is JButton.enable deprecated?

Why is Button.enable deprecated? I need to use the method of my button but it's deprecated, so it has no effect. How can I fix it? Are there any other alternatives?
WOlF
  • 115
  • 1
  • 8
8
votes
7 answers

How to get JButton default background color?

I use this myButton.setBackground(myColor) to change the JButton background color to my color, how to find it's original default background color so I can change it back? I know I can save its default background color before I change and use that,…
Frank
  • 30,590
  • 58
  • 161
  • 244
8
votes
6 answers

JButton disappears when resize

anyone know or have an idea as to why my button disappears after i resize the applet? this is my code: import java.awt.event.*; import javax.swing.*; import acm.program.*; public class button extends ConsoleProgram { public void init(){ …
8
votes
1 answer

Java, set ID for JButton

Is there anyway to set an id for a JButton. I'm used to it in Android. I'm looking for something like the following: newButton.setId(objectcounter);
user1321361
  • 131
  • 1
  • 2
  • 8
7
votes
1 answer

how to create a window with two buttons that will open a new window

I need program - main JFrame have 2 buttons button button2 When I click button it has to open new JFrame window with new options, while if I click button2 then open another window. In these 2 new windows I must add buttons like next and previous.…
Lukii007
  • 85
  • 1
  • 3
  • 4
7
votes
4 answers

Changing Font Style when Clicking on a JButton Java

How to change the STYLE of the Font when clicking on a JButton ? I'm trying to have 3 buttons each change styles to PLAIN or BOLD or ITALIC I've read the font Class API but I there is nothing like setStyle we can only getStyle I find font class in…
Sobiaholic
  • 2,927
  • 9
  • 37
  • 54
7
votes
6 answers

Creating custom JButton from images containing transparent pixels

Read edit 2 for what I'm actually missing to make it work I'm currently trying to create some custom JButtons using images created in photoshop that have an alpha parameter. So far, overriding the paint() method to draw the image has worked in the…
Jumbala
  • 4,764
  • 9
  • 45
  • 65
7
votes
2 answers

Making a JButton invisible, but clickable?

How do I make a JButton in java, invisible, but clickable? button.setVisible(false); makes the button invisible, but unclickable, is there any method that makes it invisible, but clickable? I tried…
Stan
  • 3,659
  • 14
  • 35
  • 42