###目的
JPanelとJButtonを使用して以下のレイアウトを作成する。
###問題点
ソースコードのようにcenterパネルの中にさらにbuttonを入れたのですが、
以下の図のようになってしまいます。
###ソースコード
public
1 public static void main(String[] args) { 2 Layout01D w = new Layout01D( "Layout01D" ); 3 w.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); 4 w.setSize( 350, 200 ); 5 w.setVisible( true ); 6 } 7 public Layout01D( String title ){ 8 super( title ); 9 10 JPanel pane = (JPanel)getContentPane(); 11 12 JButton buttonNorth = new JButton( "North" ); 13 pane.add( buttonNorth, BorderLayout.NORTH ); 14 15 //真ん中のパネルここから↓ 16 JPanel PCenter = new JPanel(); 17 18 //真ん中の上 19 JButton buttonnorth = new JButton( "north" ); 20 PCenter.add( buttonnorth, BorderLayout.NORTH ); 21 22 //真ん中の下 23 JButton buttonsouth = new JButton( "south" ); 24 PCenter.add( buttonsouth, BorderLayout.SOUTH ); 25 26 //真ん中の右 27 JButton buttoneast = new JButton( "east" ); 28 PCenter.add( buttoneast, BorderLayout.EAST ); 29 30 //真ん中の左 31 JButton buttonwest = new JButton( "west" ); 32 PCenter.add( buttonwest, BorderLayout.WEST ); 33 34 //真ん中の真ん中 35 JButton buttoncenter = new JButton( "center" ); 36 PCenter.add( buttoncenter, BorderLayout.CENTER ); 37 38 pane.add( PCenter, BorderLayout.CENTER ); 39 //真ん中のパネルここまで↑ 40 41 JButton buttonSouth = new JButton( "South" ); 42 pane.add( buttonSouth, BorderLayout.SOUTH ); 43 44 JButton buttonWest = new JButton( "West" ); 45 pane.add( buttonWest, BorderLayout.WEST ); 46 47 JButton buttonEast = new JButton( "East" ); 48 pane.add( buttonEast, BorderLayout.EAST ); 49 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/06 07:10