我希望面板在鼠标悬停时展开并显示按钮和内容,然后鼠标退出面板必须返回顶部原始大小。到目前为止,我只能打印一条消息:
public JPanel GUI()
{
final JPanel totalGUI = new JPanel();
totalGUI.setBackground(Color.blue);
totalGUI.setLayout(null);
//+++++++++++++++
// - - - - - - PANEL 1!
//+++++++++++++++
JPanel SearchPanel = new JPanel(); //Create new grid bag layout
SearchPanel.setLocation(5, 5);
SearchPanel.setSize(420, 120);
totalGUI.add(SearchPanel);
SearchPanel.addMouseListener(this);
return totalGUI;
}
public void mouseEntered(MouseEvent e) {
System.out.print("Mouse entered");
}
public void mouseExited(MouseEvent e) {
System.out.print("Mouse exited");
}
private static void createAndShowGUI()
{
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("RWB");
gay3 demo = new gay3();
frame.setContentPane(demo.GUI());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setSize(650, 500);
frame.setVisible(true);
}
public static void main(String[] args)
{
createAndShowGUI();
}