java - Unwanted border around JPanel -


I'm creating a form with a JPNL inside some buttons to control some graphics and things for some reason I should be 10 px less wide than JPNL and 30 px less than actual graphics which I want to put it in. What is the reason for this problem?

This code is:

  public square window {public sheep goat; Public ButtonPanel Button Panel; PaintPanel Pentale Public; Public jeffrey frame; Public window (Sheep sheep) {It. Mirror = sheep; Frame = new jefframe ("sheep simulation"); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); //frame.setSize (width, height); Border Layout Frame Layout = New Border Layout (); JPN Background = New JPN (Frame Layouts); Background.setBorder (BorderFactory.createEmptyBorder (5, 5, 5, 5)); ButtonPanel = new buttonPanel (this); Background.add (Border Layout. South, Button Panel. Button Box); Pentpanel = New PaintPanel (this); PaintPanel.setPreferredSize (new dimension (320, 240)); Background.add (border layout.citter, paintpennel); . Add frame.getContentPane () (background); Frame.pack (); Frame.setResizable (wrong); Frame.setVisible (true); }} Public class PaintPanel JPanel {public window window; Public PaintPanel (Window Window) {this.window = window; } @ Override Public Love Paint Coment (Graphics G) {G. Setler (colored blue); G.fillRect (0, 0, 320, 240); }}  

Screenshots with the favorite sequence of 320 x 240:

.

You can see that the 320 x 240 Fill JPNLL is fully, the limit of 10 px width and height of 30 px remains.

Screenshots with favorite seams of 310 x 210:

.

Now it fits 320x 240 filling at all!

Any thoughts?

Different layout managers use different rules to calculate the actual managed control sizes, i.e. You can not expect that the panel has only specific shapes if you call it 'setPreferredSize ()'

More about the algorithms used in each particular case Free for all inquiries for goal-level managers for information Do Hsus.

Also keep in mind that you can avoid using Layout Managers and fully define all sizes. 'Setbound ()' method


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -