Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing and Netbeans GUI Designer: How to remove small gaps between components when I set them invisible?

Tags:

swing

I am a newcomer to Java Swing. I am using the GUI builder of Netbeans.

I have three main panels for three different views in my application. These views can be switched by a menu on the left.

I switch these views by setting one visible and setting the other two invisible. It works but there is a little problem.

In order to achieve this, I had to put three JScrollPanes next to each other horizontally in the GUI builder. Whenever I switch to a view, the small gaps between the visible component and the invisible ones remain when the visible JScrollPane resizes itself to fill the entire window. It makes the application look quite ugly. The same thing happens when I place them vertically.

How can I fix this by using the GUI builder? I can't make changes to the code for the interface design, obviously.

Here is a very crude drawing of the problem, I hope it's clear enough: Link

Using only one JScrollPane is not an option, because they have different layout managers and will have lots and lots of components. It would not be feasible in terms of performance to render everything from the beginning when a user changes the view.

Thanks in advance,

Emre

like image 260
Emre Avatar asked Aug 06 '10 18:08

Emre


People also ask

How do I remove horizontal fixed gap in NetBeans?

Double-click the gap at the bottom of the last button. The Edit Layout Space dialog box is displayed. In the Edit Layout Space dialog box, select the Resizable option and click OK.

How do I remove layout space in NetBeans?

You now right-click the component and select "Edit Layout Space" and manually enter the value 0 in the direction with you would like the spacing removed.

How do I change the Swing look and feel in NetBeans?

You can change the of the preview by: Tools-Options Miscellaneous tab Windows tab Look and Feel:Preferred look and feel. With this the look and feel of the IDE changes too.

How do you clear a frame in Java?

If we want to clear the frame content or delete all the widgets inside the frame, we can use the destroy() method. This method can be invoked by targeting the children of the frame using winfo_children().


1 Answers

Fixed the problem myself.

You can prevent this by right clicking to each JPanel component in Netbeans, choosing "Space Around Component..." from the popup menu and set the corresponding spaces to 0 by hand.

like image 70
Emre Avatar answered Nov 23 '22 07:11

Emre