tagged [swing]

How to present a simple alert message in java?

How to present a simple alert message in java? Coming from .NET i am so used calling Alert() in desktop apps. However in this java desktop app, I just want to alert a message saying "thank you for usi...

1 Mar at 10:51

How to "Open" and "Save" using java

How to "Open" and "Save" using java I want to make an "Open" and "Save" dialog in java. An example of what I want is in the images below: Open: ![Open file dialog](https://i.stack.imgur.com/cI3JH.jpg)...

25 Oct at 18:51

How to set background color of a button in Java GUI?

How to set background color of a button in Java GUI? Below is the code which creates 9 buttons in gridlayout form on a specific pannel3. What i want is to make the background of each button black with...

13 Nov at 14:33

The Use of Multiple JFrames: Good or Bad Practice?

The Use of Multiple JFrames: Good or Bad Practice? I'm developing an application which displays images, and plays sounds from a database. I'm trying to decide whether or not to use a separate JFrame t...

22 Jul at 04:16

Format a number as currency in a JTable?

Format a number as currency in a JTable? Given a JTable where one of the columns contains a number, how do I display this number as a currency? I.e. 5 should display as $5.00 etc. Can this be done dir...

19 Apr at 18:43

How to set JFrame to appear centered, regardless of monitor resolution?

How to set JFrame to appear centered, regardless of monitor resolution? While working with Java, I find it hard to position my main window in the center of the screen when I start the application. Is ...

31 Aug at 13:49

getting integer values from textfield

getting integer values from textfield I am trying to get Integer values from my jtextfield but not able to it is showing incompatible datatypes required int found string. Is there some other way of wr...

5 Jan at 06:34

JFrame background image

JFrame background image I am creating a simple GUI, and I want to have a background image (2048 X 2048) fill up the whole window and a square to the left top corner where the occasional 64 X 64 image ...

21 Dec at 20:33

How do you add an ActionListener onto a JButton in Java

How do you add an ActionListener onto a JButton in Java How do I add action listeners to these buttons, so that from a main method I can call `actionperformed

How to Set Focus on JTextField?

How to Set Focus on JTextField? I make my game run without mouse so using pointer is not a choice. High Score menu will show when player lose. this is my code I have tried ``` highScore.setFocusable...

17 Jul at 10:50

How to make a JFrame button open another JFrame class in Netbeans?

How to make a JFrame button open another JFrame class in Netbeans? I have a `JFrame` class and it was made in the design section on Netbeans. I am trying to make a log in button that takes closes the ...

14 Jul at 06:49

Java: Difference between the setPreferredSize() and setSize() methods in components

Java: Difference between the setPreferredSize() and setSize() methods in components What is the main difference between `setSize()` and `setPreferredSize()`. Sometimes I used [setSize()](http://docs.o...

18 Jul at 18:31

JFileChooser.showSaveDialog(…) - preserve suggested file name after changing directory

JFileChooser.showSaveDialog(…) - preserve suggested file name after changing directory There are already some questions about how to set a [default file name](https://stackoverflow.com/questions/35667...

23 May at 12:11

Adding items to a JComboBox

Adding items to a JComboBox I use a combo box on panel and as I know we can add items with the text only But some times I need to use some value of the item and item text like in html select: Is there...

26 Jul at 19:27

How do I change JPanel inside a JFrame on the fly?

How do I change JPanel inside a JFrame on the fly? To put it simple, there's a simple java swing app that consists of JFrame with some components in it. One of the components is a JPanel that is meant...

Triangle Draw Method

Triangle Draw Method I have trouble drawing a triangle with the `draw(Graphics g)` method in Java. I can draw a rectangle like so: Where p represents "the top left corner of the shapes". How would I

16 May at 22:18

Java Swing or Windows Forms for desktop application?

Java Swing or Windows Forms for desktop application? I am writing a fat client application that I would ideally like to be cross-platform, but may settle for Windows-only based on the following: - - -...

19 Feb at 22:37

Getting a HeadlessException: No X11 DISPLAY variable was set

Getting a HeadlessException: No X11 DISPLAY variable was set ``` Exception in thread "main" java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which...

17 Dec at 13:24

JComboBox Selection Change Listener?

JComboBox Selection Change Listener? I'm trying to get an event to fire whenever a choice is made from a `JComboBox`. The problem I'm having is that there is no obvious `addSelectionListener()` method...

8 Jan at 13:30

How to set a transparent background of JPanel?

How to set a transparent background of JPanel? `JPanel` My frame is has two `JPanel`s: - - is overlapping . The is working as a background and it loads image from a remote URL. On I want to draw sha...

21 Sep at 13:18

Making a component less sensitive to Dragging in Swing

Making a component less sensitive to Dragging in Swing A `JComponent` of mine is firing a `mouseDragged` event too vigorously. When the user is trying to click, it interprets is as a drag even if the ...

6 Feb at 21:27

Get combobox value in Java swing

Get combobox value in Java swing I need to get the integer value of the combobox in Swing. I have set an integer value as id for the combobox.I tried combobox.getSelectedItem() and combobox.getSelecte...

17 Aug at 04:15

Java - Check if JTextField is empty or not

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 ...

JOptionPane Yes or No window

JOptionPane Yes or No window I am trying to create a message with a Yes or No button. Then a window will appear with a certain message that depends on if the user clicked Yes or No. Here is my code: ...

6 Dec at 15:54

How to add text to JFrame?

How to add text to JFrame? So I am designing a JFrame using Eclipse WindowBuilder. This specific frame is an error message stating that the user provided invalid credentials. I have added a button to ...

1 Dec at 18:55