I have some experience with Java but I am new with Swing. I am trying to run a very simple example but I run into an annoying problem that I cannot solve. I am trying to open a white window and draw a blue rectangle. Somehow, the rectangle only shows up after I manually resize the window. I have tried
Tag: swing
Neither ActionListener nor MouseListener added to JButton works for setting color in PaintComponent in JPanel
I am creating a Java program to simulate Microsoft Paint in Windows 95. There is a color palette in the bottom. Clicking any color in the palette will change the color of the painting tool like pencil. I tried to use Graphics2D to set each color for the tool according to the button clicked in the palette. I tried to
java form does not display [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 months ago. Improve this question I am very new to java forms. Sorry about this easy question, I’ve searched too many forums but still couldn’t find the issue. I have
Nimbus takes precedence over manually defined renderer?
Making a GUI in Swing (NetBeans 15, Sun JDK 19.0.1), i’m trying to set custom background color for JTable rows and encountered issues with boolean cells, and i can’t seem to be able to make the background uniform across all cells. Please note that the following code tries to paint the background for the whole table, but my target is
Horizontal JScrollPane inside vertical JScrollPane
Good afternoon! It is necessary to make a list (vertical) from lists of events (horizontal). There are at least 2 problems: the area of the list of events (horizontal scrolling) expands beyond the borders of the panel. Apparently, the problem is with Layout, but I can not find the right combination; horizontal scrolling does not work (probably due to the
Painting method paints things from other components
I am trying to make a simple Java program with GUI using Java Swing. I have painting panel (gPanel) in the center of the screen, panel with buttons (buttonSet) in the west and panel with labels (labelPanel) in the east. To paint over gPanel I use paintComponent method and since I have two buttons, which are supposed to draw different
Java Swing: SwingWorker uncaught exceptions are not getting picked up by Thread.UncaughtExceptionHandler
My Swing program creates many threads and it’s getting hard to handle exceptions properly. I would like to rely on a global exception handler, and i came across Everything seemed to work fine, until i introduced a SwingWorker to perform a background task. Apparently, if an exception occurs inside my swing worker and it is not handled inside it, the
Change the mouse cursor when shift key is pressed
I have a subclass PointPanel of JPanel, where I want to implement the following behavior: If the mouse hovers the instance and the shift key is pressed, the mouse cursor changes to the hand cursor; if the shift key is released, the mouse cursor changes back to the default cursor. In order to achieve this, I tried to add a
Align JLabel using SwingConstants
Why is my JLabel text not aligned to the left or center? Is the FlowLayout the issue? Both of the texts are just appearing at the top, next to each other and I can’t fix this. Main Class Constructor class Answer Refer to Laying Out Components Within a Container which is a lesson in the Creating a GUI With Swing
How can I call the mouse right click event in SwingGui?
I have a table. If I right-click I got a JPopUpMenu but before the pop-up I want to select the row where the right-click event is done. Here is what I’ve tried. In that event, I cannot get any output from the console when I right-click. However, when I left-click, points are printed to the console. java.awt.Point[x=105,y=76] So, this event