I am trying to combine in the same window two JPannel
, in one enter a GridLayout
and in another to put a JButton
that is not included in the Grid.
The Grid view is displayed correctly but the JButton
is not displayed in the window.
The code is as follows:
public class Interface extends JFrame {
//-----ATRIBUTOS-----
private JPanel contentPane;
private JPanel panel2;
private GridLayout gridLayout;
private BorderLayout borderLayout;
private JButton jButton;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Interface frame = new Interface();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
//----------CONSTRUCTOR--------
public Interface(){
setTitle("Sudoku");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(25,25,650,430);
contentPane = new JPanel();
panel2 = new JPanel();
panel2.setBorder(new EmptyBorder(400,250,20,20));
setContentPane(panel2);
contentPane.setBorder(new EmptyBorder(5,5,150,300));
setContentPane(contentPane);
contentPane.setLayout(null);
//Establecemos el gridLayout
gridLayout = new GridLayout(5, 5);
contentPane.setLayout(gridLayout);
//Rellenamos el gridLayout
for (int i =0;i<gridLayout.getRows();i++){
for (int j=0;j<gridLayout.getColumns();j++){
contentPane.add(new JTextField());
}
}
//Establecemos el borderLayout
borderLayout = new BorderLayout();
panel2.setLayout(borderLayout);
//Botón de validar
jButton = new JButton("VALIDAR");
jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
jButton.setBounds(0, 0, 100,150);
panel2.add(jButton);
}
}