親JFrame以外のレイアウトのJPanelを使用できるかどうか知りたいです。例えば。ボーダーレイアウトのJFrameがあり、JPanelが埋め込まれていて、レイアウトが異なる場合。出来ますか ?
私はそれをやろうとしています。しかし、このように、そのJPanelのコンポーネントは表示されていません。
ここに問題の詳細があります:
私はJFrameを持っていて、そのレイアウトはBorderLayoutです。このフレームにJPanelを追加しています。JPanelのレイアウトを設定しない場合。JPanelのすべてのコンポーネントがウィンドウに表示されていますが、JPanelのグリッドレイアウトを設定すると、JPanelのコンポーネントが表示されません。コンポーネントを揃えるために、JPanelにレイアウトを追加しています。以下は私のコードです:
メインクラス、フレームクラス、Jpanelクラスがあります。
public class AppMain {
public static void main(String[] args) {
AppPage1 page1 = new AppPage1("test");
page1.setVisible(true);
}
}
public class AppPage1 extends JFrame {
public AppPage1(String title) throws HeadlessException {
super(title);
this.setLayout(new BorderLayout());
addWindowListener(new WindowAdapter() {
public void windowOpened(WindowEvent e) {
setExtendedState(MAXIMIZED_BOTH);
}
});
//Panel for logo
JLabel testLogo = new JLabel("");
testLogo.setIcon(new javax.swing.ImageIcon("test.JPG"));
List<JComponent> componentList = new ArrayList<JComponent>();
componentList.add(testLogo);
PagePanel logoPanel = new PagePanel(componentList,null);
this.add(logoPanel, BorderLayout.NORTH);
//Panel for Button and checkboxes
JLabel panelTitle = new JLabel("test Wizard");
JRadioButton rdButton_ExistingConfigurationFile = new JRadioButton("Existing Configuration File");
JRadioButton rdButton_ConfigureNewPropertyFile = new JRadioButton("Configure new Property File");
componentList = new ArrayList<JComponent>();
componentList.add(panelTitle);
componentList.add(rdButton_ExistingConfigurationFile);
componentList.add(rdButton_ConfigureNewPropertyFile);
PagePanel buttonPanel = new PagePanel(componentList,new GroupLayout(this));
this.add(buttonPanel, BorderLayout.CENTER);
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
validate();
}
}
public class PagePanel extends JPanel {
public PagePanel(List<JComponent> componentList, LayoutManager layOutManager) {
this.setBackground(Color.decode("#4E6987"));
if (layOutManager != null) {
this.setLayout(null);
}
for (JComponent jComponent : componentList) {
jComponent.setBackground(Color.decode("#4E6987"));
this.add(jComponent);
}
}
}
事前に感謝しますRaviKumar