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
104
votes
5 answers

Creating a custom JButton in Java

Is there a way to create a JButton with your own button graphic and not just with an image inside the button? If not, is there another way to create a custom JButton in java?
Anton
  • 12,285
  • 20
  • 64
  • 84
57
votes
9 answers

Java: using an image as a button

I would like to use an image as a button in Java, and I tried to do this: BufferedImage buttonIcon = ImageIO.read(new File("buttonIconPath")); button = new JButton(new ImageIcon(buttonIcon)); But this still shows the actual button behind the image,…
3sdmx
  • 766
  • 2
  • 6
  • 10
52
votes
1 answer

How can I add a space in between two buttons in a boxLayout?

I have four buttons in a BoxLayout group. This is just a sample of two because it's all repeated code. I want to create a slight space between each button so they don't run into each other. I have tried practically every method in the…
Susie
  • 565
  • 1
  • 6
  • 9
50
votes
11 answers

How do I add an image to a JButton

I am trying to add an image to a JButton and I'm not sure what I'm missing. When I run the following code the button looks exactly the same as if I had created it without any image attribute. Water.bmp is in the root of my project folder. ImageIcon…
kevinstueber
  • 2,926
  • 3
  • 26
  • 26
46
votes
3 answers

Transparent JButton

Is it possible to make a JButton transparent (including the border) but not the text? I extend swing's JButton and override this: @Override public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g.create(); …
Rendicahya
  • 4,205
  • 7
  • 36
  • 56
44
votes
3 answers

How do I save preference user settings in Java?

For example, I have a window with a preference button. I want to make it so that when user press the preference button and checks his/her appropriate options and press ok, it saves the preference, then when user presses run on the main window, it…
js0823
  • 1,843
  • 8
  • 24
  • 36
43
votes
4 answers

Creating a custom button in Java with JButton

I am trying to create a button that has a custom shape (hexagon), but otherwise acts like a normal JButton would (that is, works with an ActionListener). I have created a class that extends AbstractButton, but it doesn't seem to be sending events to…
rybl
  • 1,609
  • 3
  • 14
  • 22
38
votes
3 answers

resizing a ImageIcon in a JButton

I am creating a JButton which includes a specific ImageIcon. The main issue is that the original icon size is much bigger than the button size. As result when the button is displayed, only part of the icon can be seen. What is the method that…
Anto
  • 4,265
  • 14
  • 63
  • 113
38
votes
3 answers

How do you add an ActionListener onto a JButton in Java

private JButton jBtnDrawCircle = new JButton("Circle"); private JButton jBtnDrawSquare = new JButton("Square"); private JButton jBtnDrawTriangle = new JButton("Triangle"); private JButton jBtnSelection = new JButton("Selection"); How do I add…
user37037
  • 381
  • 1
  • 3
  • 3
37
votes
1 answer

Swing JButton: Icon above Text

How can I create a JButton in Swing with the icon above the text?
codegy
  • 2,259
  • 4
  • 25
  • 24
37
votes
7 answers

How to create a JButton with a menu?

I want to create a Toolbar in my application. If you click a button on that toolbar, it will pop up a menu, just like in Eclipse's toolbar. I don't know how to do this in Swing. Can someone help me please? I've tried Google but found nothing.
Kien Truong
  • 11,179
  • 2
  • 30
  • 36
35
votes
6 answers

Disable JButton focus border

I have a problem with JButton in Java. Basically, I want to disable the button's border (the button is added to JDesktopPane ). Here is my code : JButton j = new JButton("BUTTON"); j.setIcon(icon1); //icon1 : icon// j.setFocusable(true); …
Cocc Cocc
  • 371
  • 1
  • 5
  • 7
33
votes
12 answers

Java - Check if JTextField is empty or not

So I got know this is a popular question and already found the solution. But when I try this it doesn't work properly. My JTextField is empty and the button isn't enabled. When I write something in my textfield the button doesn't get enabled. So my…
ColdStormy
  • 562
  • 1
  • 6
  • 15
30
votes
6 answers

Making a JButton clickable inside a JTable

Here is the screenshot of what I want to do : What's happening there is the JButton shows correctly but nothing happens when I click on it. After some search, I've found that the Object returned by table.getValueAt() is a String instead of a…
noli
  • 3,535
  • 3
  • 18
  • 20
29
votes
11 answers

How to add action listener that listens to multiple buttons

I'm trying to figure out what i am doing wrong with action listeners. I'm following multiple tutorials and yet netbeans and eclipse are giving me errors when im trying to use an action listener. Below is a simple program that im trying to get a…
user519670
  • 685
  • 3
  • 15
  • 23
1
2 3
99 100