Я это ActionListener добавил к кнопке:JButton удаление всех остальных JComponent от JPanel
//The ActionListener for the home button
ActionListener homeActionListener = new ActionListener(){
public void actionPerformed(ActionEvent e) {
removeAll();
Home home = new Home();
add(home);
}
};
Это код для JPanel и JButton:
//creating the jpanel which will hold the buttons
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(null);
buttonPanel.setBounds(0,0,600,100);
buttonPanel.setBackground(Color.GRAY);
add(buttonPanel);
//creating the jbutton to send the user to the home page
JButton home = new JButton("Home");
home.setBounds(25,25,100,50);
buttonPanel.add(home);
Как я могу сделать это так, он удаляет каждый компонент jframe, за исключением того jpanel, который называется buttonPanel?
У вас есть другие функции 'JPanel' в вашей форме? – BitNinja
Не уверен, что это возможно (нет моего компьютера в данный момент), но попробуйте вызвать removeAll() на панели кнопок, и он должен удалить элементы внутри панели – user2277872