Skip to content

Tag: swing

Rectangle shows up only after resizing on JFrame

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

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 f…

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; horizonta…

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 s…

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 t…

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 Wi…

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…