In my program I try to show the JFrame
when I put the mouse on JLabel
and close the JFrame
when I remove the mouse from JLabel
.
How can I do it?
I tried below way, but I am getting flashing windows continuously(popup and close continuously)
public class NewJFrame extends javax.swing.JFrame {
NewJFrame1 frame = new NewJFrame1();
public NewJFrame() {
initComponents();
}
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
//======================================================================
jLabel1.addMouseListener(new MouseAdapter()
{
public void mouseEntered(MouseEvent e)
{
frame.setVisible(true);
}
});
jLabel1.addMouseListener(new MouseAdapter()
{
public void mouseExited(MouseEvent e)
{
frame.setVisible(false); //Hide window
}
});
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("Testing ");
//======================================================================
pack();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
public javax.swing.JLabel jLabel1;
}
In between these lines//============
I have the main code
How to display JFrame
when I put mouse on JLabel
and how to close the JFrame
when I remove the mouse from the JLabel
?
When I remove the below code , and when I place the mouse on JLabel
I am getting JFrame
popup , but I need to close the JFrame popup when I remove the mouse from JLabel
.
jLabel1.addMouseListener(new MouseAdapter()
{
public void mouseExited(MouseEvent e)
{
frame.setVisible(false); //Hide window
}
});