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
17
votes
6 answers

Howto make JButton with simple flat style?

whats the most simple way to make a JButton only show the background color? I don't need any other effects like borders, 3D-look or hover-highlighting. Thanks in advance.
c0d3x
  • 2,593
  • 6
  • 23
  • 18
17
votes
2 answers

How to open a new window by clicking a button

As a part of my program, I need to have a button that when the user click on it, it opens a new window. Well I guess I should have a class that make the frame and call it by the button. but I don't have any idea to start. I just got my button in the…
Alex Jj
  • 1,343
  • 10
  • 19
  • 30
17
votes
1 answer

How to change text color of a JButton

I am writing a simple minesweeper game and it works now, but I am working on the pretty details like making each number a different color. I keep running into errors when I try to set the text color on the JButton. I can change the text easily…
Kurt E
  • 367
  • 1
  • 2
  • 9
15
votes
4 answers

Something seems wrong with the layout, JButton showing unexpected behaviour at resize of the window

JRE Version 1.7 Update 3 EXPECTED BEHAVIOUR As I run the program, it works as expected, everything works smoothly. As when I click on STOP JButton the animation stops and the text on the same JButton changes to START. Now when i click on BALL COLOUR…
nIcE cOw
  • 24,468
  • 7
  • 50
  • 143
15
votes
4 answers

Word Wrap in JButtons

Is it possible to achieve automatic word wrap of texts in JButtons? I am having few dynamic buttons which I create on runtime. I want to put word wrap feature on the buttons so that I can see some better test on buttons. Is it possible to do that?
Deepak
  • 6,684
  • 18
  • 69
  • 121
15
votes
5 answers

How do I programmatically send ActionEvent to JButton?

How do I programmatically send an ActionEvent (eg button pressed/ACTION_PERFORMED) to a JButton? I know…
Anon
  • 203
  • 1
  • 2
  • 6
15
votes
7 answers

Simple Dropdown menu in Java

I am working on a very simple GUI in Java. In this GUI I want to display: A label with some text on the top of the page A JComboBox under the mentioned label A JButton under the mentioned JComboBox Here's my code: import…
NoobNe0
  • 385
  • 1
  • 6
  • 20
14
votes
2 answers

Add icons to JButton using custom font from AwesomeFont and unicode characters in Java Swing?

I have a JButton and I want to add an icon to it. I would like to use the font based icons from FontAwesome which provides a TrueType font file. The icon I am trying to add is the play button icon. The play button icon in the css file for…
rmontgomery429
  • 14,660
  • 17
  • 61
  • 66
14
votes
3 answers

Change JButton gradient color, but only for one button, not all

I want to change JButton gradient color, i found this, http://java2everyone.blogspot.com/2009/01/set-jbutton-gradient-color.html, but i want to change gradient for only one button, not all button
help
  • 809
  • 5
  • 18
  • 35
14
votes
4 answers

How to put Hover effect on jbutton?

I am trying to create a Java Desktop application where I am using two buttons. I want to add hover effect in those buttons. I want: When I click any button it should change its background color. How can I achieve it? Here is my code: public class…
user3456343
  • 252
  • 3
  • 7
  • 21
14
votes
7 answers

How to handle cancel button in JOptionPane

I had created a JOptionPane of type showInputDialog. When it opens it, it shows me two buttons: OK and Cancel. I would like to handle the action when I push on Cancel button, but I don't know how to reach it. How can I get it?
Mazzy
  • 13,354
  • 43
  • 126
  • 207
13
votes
1 answer

How to clear the JTextField by clicking JButton

Possible Duplicate: JButton needs to change JTextfield text How do I clear a JTextField when a JButton is clicked?
Monte
  • 131
  • 1
  • 1
  • 3
13
votes
2 answers

Why does the Java doClick() use 68 milliseconds when it calls doClick(pressTime)?

In doClick() when it calls doClick(pressTime) does it send 68 milliseconds? Why did they decide on 68 instead of a more round number? Is it a completely arbitrary number? From Java AbstractButton: public void doClick() { doClick(68); }
Ian
  • 354
  • 4
  • 13
13
votes
2 answers

Put JButton in bottom right

I need to put a button in the bottom right of an otherwise empty JPanel +-----------------------------------+ | | | | | | | …
Lucas
  • 1,869
  • 4
  • 20
  • 36
12
votes
6 answers

Java Swing JFrame Layout

I just wrote a simple code where I want a textfield and a button to appear on the main frame, but after running all I see is the textfield. If I write the code of the button after the textfield then only the button is displayed. Any idea why? …
DanMatlin
  • 1,212
  • 7
  • 19
  • 37