I have a JSpinner with SpinnerDateModel. I want when users click on any part of the editor (the date, month, or year), it will automatically select them. So I wrote this: But when the first time it clicked, nothing happened. Although when I click it again, it works perfectly. Where’s wrong with my code? Answer From the documentation of MouseAdapter#mousePressed():
Tag: swing
Why is the swing gui behaving strange?
I just started making my Java application on Minesweeper. The idea is a GridLayout JPanel inside a JFrame. But after executing the program I get some weird window. There is this strange gray corner on the upper left corner. And the tiles don’t all show. Somehow hovering the mouse over them shows. The program produced this ugly abomination. How to
traverse an array in GUI Java
I am doing a questionnaire with questions and written answers. I need that when adding the answer, press the main button, tell me if it is correct or not and show me the other question of the array, until the array is finished. Here I upload the whole code. Answer You have the right idea, but you need to process
Why is my image not being added? JavaSwing
I made this program, assume I have an extra src folder in my buildpath with the monkiflipppp.gif there. It just runs and has a button, but the button won’t actually do anything… Not sure if I need …
Swing BorderLayout: Make no space between buttons, no center gap
I have this code: When I run it, it shows: However when I resize this window: How do I make it so that buttons take up 100% of the windows, like this: I tried to do this: but it worked even worse: I also tried: but it gave the original result. Answer This layout can be easily achieved by using
GUI Elements Not Showing Immediately
I made a redesign to my gui in java and it is facing an issue, the icons don’t show until i grab the gui and shake it, sometimes they show half then i have to grab it by the mouse and check it again …
How to set JFrame in fullscreen using users native resolution?
I am trying to create a little game for a project in university. Since I need to update the screen permanently I am looking for a good render loop implementation. It should be full screen. I found this on gamedev.net – Java Games: Active Rendering: I executed the code and there are two things I am wondering about: My display
I want the city selected in the first combo box not to appear in the second
If I choose a city FROM: JComboBox then it shouldn’t appear in TO: combo box. How can I code the ActionListener of this action listener? Screenshot Code: Answer I reworked your code to get away from static. You only need one list of cities for your from and to JComboBoxes. You use an ActionListener to listen for changes in the
Is there a way to make multiline JLabel text flow around the icon?
Currently in my project I have multiple JLabels each with their own text and icon The problem I have is that the icon take a whole left side to it self The effect I’m trying to achieve is to make the text flow around the icon Is this effect possible with JLabel? if not, is it possible with any other
How to align multiple lines of JOptionPane output dialog messages by “:”?
I need to make the output in 3 lines and also aligned by “:”, using JOptionPane.showdialogmessage(): *note the alignment of the “:” I have tried manually adding spaces before each “:” but still these 3 lines do not strictly align: Here is the output screenshot: What is the easiest way to realize this alignment? Thanks P.S.: This is my first