Можно ли добавить JPanel с JButtons в Split JPanel? Прямо сейчас у меня есть JPanel с JButtons, добавленным в JFrame, но я хочу его на JPanel с другими JPanels. Когда я пытаюсь сделать это, я получаю совершенно пустой JPanel с разделителями.JButtons в JPanel в другом JPanel
______________________________________________________________________________
public class Panel extends JPanel implements Runnable, ActionListener {
public Panel(){
JFrame frame = new JFrame();
ctsMenu = new JPanel(new GridLayout(2,2));
ctsMenu.setPreferredSize(new Dimension(500,500));
for (int iRows = 0; iRows < 2 ; iRows++){
for (int iColumns = 0; iColumns < 2; iColumns++){
sGrid[iRows][iColumns] = new JButton ("("+iRows+","+iColumns+")");
ctsMenu.add(sGrid[iRows][iColumns]);
sGrid[iRows][iColumns].addActionListener(this);
panel.add(ctsMenu);
}
}
sGrid[0][0].setText("A");
sGrid[0][1].setText("B");
sGrid[1][0].setText("C");
sGrid[1][1].setText("D");
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);
}}
____________________________________________________________________
public MainFrame()
{
setTitle("Split Pane Application");
setBackground(Color.GREEN);
JPanel topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
getContentPane().add(topPanel);
createPanel1();
createPanel2();
createPanel3();
createPanel4();
splitPaneV = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
topPanel.add(splitPaneV, BorderLayout.CENTER);
splitPaneV.setDividerLocation(300);
splitPaneV.setLeftComponent(gamePanel);
// gamePanel.addKeyListener(new KeyListener());
gamePanel.setFocusable(true);
gamePanel.requestFocusInWindow();
splitPaneV.setRightComponent(panel3);
}
}
public void createPanel1(){
// deleted to take up less space
}
public void createPanel2(){
// deleted to take up less space
}
public void createPanel3(){
panel3 = new Panel();
}
public void createPanel4(){
//deleted to take up less space
}
}