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
0 answers

How to create a menu like the image

I want to create a menu, like this image : It's a sort of button, when the user clicks in that button a menu appears, with diffrent options. Also, when the user choses one of those option,another submenu appears, Just as is shown the image. I don't…
abdou amer
  • 819
  • 2
  • 16
  • 43
1
vote
1 answer

How to generate a JButton based on user input?

How to generate a JButton based on user input? I want to create a Java Swing GUI program that allows a user to upload his/her pictures on a GUI. If the user selects multiple picture using a file chooser, the window will generate buttons that have…
dens14345
  • 192
  • 1
  • 4
  • 17
1
vote
1 answer

doClick(), and Simon: All buttons will unpress at the same time instead of individually

Hi I'm new to stackoverflow so bear with me if I make mistakes. I'm making this Java Simon Says Game for a class project. It works by a random number generator for each sequence#. I show the sequence through doClick() but remove the actionlisteners…
Nathaniel
  • 13
  • 2
1
vote
2 answers

Using removeActionListener but not removing - JAVA

I have created part of a Tic-Tac-Toe game, and I am trying to make sure the "Player VS Player" button becomes disabled once a game is started. I am new to Java swing and all of the graphics, so please, any help is appreciated. I have used…
Sam Mitchell
  • 194
  • 2
  • 18
1
vote
3 answers

Simple GUI guidance. Can I stick with BorderLayout or do I need something else?

I'm trying to create a GUI for a personal project. I have a file chooser, a console area, a text field (with label), a button panel(2 buttons) and finally a "drop zone" area. The GUI is divided vertically in half with the console on the right. On…
Ryan
  • 47
  • 1
  • 1
  • 6
1
vote
1 answer

JButton Set X Location not working

I have a JWindow which has a JLabel and JButton in a JPanel. I'm trying to set the location of the JButton to the center. For some reason, setting the y location works, but the x location doesn't change. What is wrong with my code? JWindow window =…
bobbobbob
  • 92
  • 1
  • 12
1
vote
0 answers

Java-Creating User-Generated JButtons

Thanks for trying to help. First off, I'm trying to create a sort of list-program that can allow you to create, manage, and view various lists. However, I ran into a problem when I was deciding how to implement changing the lists. I wanted to do…
Rezkin
  • 441
  • 1
  • 6
  • 17
1
vote
3 answers

JButton not changing size

I've researched the ways to change the size of a jbutton to be displayed on a JFrame. I am trying both the button.setSize(200,200) and button.setPreferredSize(new Dimension(200,200)), but it does not change. Here's the code: import…
Arcthor
  • 53
  • 4
  • 8
1
vote
2 answers

Programming a JButton to create an object when clicked

EDIT: I want this window to be able to create multiple user profiles, so it needs to create more variables than just u1. The idea of the program is to mimic a social network. I don't know how to do this, however. Thanks! I'm new to java GUI. So far,…
freezefry
  • 138
  • 4
  • 21
1
vote
0 answers

Using JButton's with 2 JTextField

I cant seem to make JButtons work with 2 JTextField, My Goal is: 1.if App starts and no JTextField is focused(selected) by user : if user presses JButton,append to JTextField tf[0]. 2.if JTextField tf[0] is focused(selected) & user presses JButton…
Jaymit Desai
  • 153
  • 1
  • 2
  • 11
1
vote
1 answer

Right click on JButton to lock it and change its colour Java

I am a beginner at java so am attempting to create a minesweeper game. I have a grid full of JButtons that when clicked reveal numbers or mines. I want to add "flags" so when I right click on any button it changes colour - showing it has been…
JOG
  • 15
  • 3
1
vote
4 answers

Remove JButton padding in MigLayout

I have a small "popup" like this: But I don't want the padding around the button, I want it to be as small as it can be with the supplied text. btn.setMargin(new Insets(1, 1, 1, 1)); panel.add(lbl,…
Indrek
  • 6,516
  • 4
  • 29
  • 27
1
vote
1 answer

JButton child does not update text

I'm building a game where the object is to move a knight around a world and be able to fight other knights. I've got a class Main that starts the game: public class Main { public static void main(String[] args) { new Game(); } } A…
1
vote
0 answers

Resetting JTextfield Within JButton Actionlistener

I'm using CardLayout to develop a budget application. My code below creates a JPanel main_panel that houses a homepage JPanel card called "homePageCard" and another JPanel card called "addItemCard". When I click on the JButton "addItemButton"…
1
vote
1 answer

JButton Windows Look and Feel

I want get this appearance for a JButton: I have tried to change the Look and Feel to Windows this way: UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); but it is shown as: Thanks in advance!
Héctor
  • 24,444
  • 35
  • 132
  • 243