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
10
votes
1 answer

How to set a Single key Mnemonic in button in Java?

I am working on a project and I want to set Mnemonic on buttons. But the problem is Mnemonic works on pairing key example (Alt+F) etc. But I want it to be on single key.
hemant
  • 564
  • 2
  • 13
  • 37
9
votes
5 answers

Java - Call Method via JButton

How can I call a method by pressing a JButton? For example: when JButton is pressed hillClimb() is called; I know how to display messages etc when pressing a JButton, but want to know if it is possible to do this? Many thanks.
Mus
  • 7,290
  • 24
  • 86
  • 130
9
votes
2 answers

Place components at arbitrary (x,y) coordinates

I want to place some buttons in a JPanel at random positions (x,y), and these layout classes are annoying. Is this even possible in Swing?
vlad-ardelean
  • 7,480
  • 15
  • 80
  • 124
9
votes
3 answers

action listener to JDialog for clicked button

I have main application where is table with values. Then, I click "Add" button, new CUSTOM (I made it myself) JDialog type popup comes up. There I can input value, make some ticks and click "Confirm". So I need to read that input from dialog, so I…
Paulius Vindzigelskis
  • 2,121
  • 6
  • 29
  • 41
9
votes
2 answers

how to hide background of JButton (which containt icon image)?

I have this code to make a Jbutton with icon image ,and it works.But the problem is that the borders and background of button don't disappear. I want only the icon image is appear without borders & background of button. I tried to set…
Jason4Ever
  • 1,439
  • 4
  • 23
  • 43
9
votes
1 answer

Make a button round

I'm trying to make a JButton round at the (x,y) coordinates of (150,210). I want the button to be an oval of the size (40,40). And the buttons background color red. It doesn't need text, so I should get a button to whatever size I want, right? I am…
zach glenn
9
votes
3 answers

JButton expanding to take up entire frame/container

Hey everyone. I'm trying to make a swing GUI with a button and a label on it. im using a border layout and the label ( in the north field ) shows up fine, but the button takes up the rest of the frame (it's in the center field). any idea how to…
Michael Hoyle
  • 93
  • 1
  • 1
  • 3
9
votes
3 answers

Adding Buttons inside cell of JTable along with data?

Is it possible to add buttons inside the JTable cell along with data? What I am trying to do is to create a table with columns which display data(number) from the database, and two buttons to increase/decrease the number inside the same cell. |ID |…
Todd
  • 219
  • 1
  • 5
  • 12
9
votes
3 answers

Java JButton only image?

I set the icon of my button to an .png I made in photoshop, but instead of just the image being visible, then there's still the button border or what ever you wish to call it. I want the button to just be:
Paludan
  • 622
  • 1
  • 5
  • 21
9
votes
1 answer

Making Image button look pressed/clicked in Swing

I created a JButton which has an image set as an icon representing the button. Now, I've set setContentAreaFilled(false); setBorderPainted(false); setOpaque(false); the properties which this makes an image-button look nice with no borders or…
Rohan
  • 871
  • 1
  • 16
  • 32
9
votes
1 answer

Change Default Buttons in Java to Make Them Look "Better"

I'm essentially trying to mimic the default windows xp simple calculator. When I change the background colours of the buttons in Java it makes them look very flat and "boring". I want to make the buttons look as close as possible to the buttons in…
ComputerLocus
  • 3,448
  • 10
  • 47
  • 96
8
votes
6 answers

Disable JButton, while background job, to avoid multiple clicks

I need to stop user making multiple clicks on a JButton while the first click still execute. I was able to came with a solution for this issue but I do not completelly understand why it's working. Bellow I posted the code (trimmed to a minimum)…
Alex
  • 5,510
  • 8
  • 35
  • 54
8
votes
3 answers

Auto-resizing JButton Icon

so I have this JButtons to which I add Icons. The Icons are too large initially, so I resize them beforehand, and it works fine. Except that when I resize the window, the JButtons change size, but not the Icons, which is problematic. Is there a way…
Cristol.GdM
  • 505
  • 2
  • 5
  • 21
8
votes
7 answers

Get button name from ActionListener?

I have scoured the internet but can't find an answer to this : I'm using a for loop to create 36 buttons called a1, a2, etc. and assigning each of them a unique Action Command at the same time. Later on I wanted to get the name of the button from…
James MV
  • 8,569
  • 17
  • 65
  • 96
8
votes
3 answers

JTable with a “close” button in the column header

I am trying to create a table with custom column headers. I want the column headers to include a button that users can click on. The function of the button will be to remove the column from the table. Essentially, I am trying to build something…
Aleksey
  • 81
  • 1
  • 2