アプリケーションの動作を理解するのに問題があります。単純なウィンドウ ( 1000x700px ) を 2 つの部分 (それぞれ幅250pxと750px ) に分割して作成したいと考えています。次のコードを試しました:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Example extends JFrame
{
private static final long serialVersionUID = 1L;
public Example()
{
this.setSize(1000, 700);
this.setTitle("Example");
this.setResizable(false);
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
JPanel navigation_panel_wrap = new JPanel();
JPanel content_panel_wrap = new JPanel();
navigation_panel_wrap.setPreferredSize(new Dimension(250, 700));
content_panel_wrap.setPreferredSize(new Dimension(750, 700));
content_panel_wrap.setBackground(Color.green);
navigation_panel_wrap.setBackground(Color.red);
this.getContentPane().add(navigation_panel_wrap);
this.getContentPane().add(content_panel_wrap);
}
public static void main(String[] args)
{
Example example = new Example();
example.setVisible(true);
}
}
ご覧のとおり、 JFrame
(水平および垂直のギャップがゼロFlowLayout
の代わりに)レイアウトマネージャーを手動で設定しました。もちろん、メソッドと パラメーターを使用するよりも and を使用できますが、 の何が問題なのかを理解したいと思います。アプリケーションを実行すると、次のようになります (緑なし): BorderLayout
BorderLayout
add()
BorderLayout.EAST
BorderLayout.WEST
FlowLayout
JPanel
たとえば、幅を減らしcontent_panel_wrap
て750pxではなく744pxにすると、すべてが正しく機能します。
問題は、これらの奇妙な 6 ピクセルは何ですか? この値がすべてのオペレーティング システムで一定であるとは限らないため、その起源を理解したいと考えています。