This is a popup Jpanel with a JTextarea, but I have one problem. When I move the mouse on the JTextarea it blinks. Why does this happen?
In debug mode a mouse move generates a mouseExited event.
public class PopUpPanel extends JPanel {
public PopUpPanel(final String info, int x_pos, int y_pos) {
final JTextArea textArea = new JTextArea(info);
add(textArea);
setBackground(Color.WHITE);
textArea.setVisible(false);
setBounds(x_pos, y_pos, 20, 20);
setOpaque(false);
setVisible(true);
final Rectangle bounds = getBounds();
MouseInputAdapter mouseHandler = new MouseInputAdapter() {
@Override
public void mouseEntered(final MouseEvent e) {
Rectangle bound = getBounds();
bound.width = textArea.getPreferredSize().width;
bound.height = textArea.getPreferredSize().height;
setBounds(bound);
textArea.setOpaque(true);
textArea.setVisible(true);
}
@Override
public void mouseExited(final MouseEvent e) {
textArea.setOpaque(false);
textArea.setVisible(false);
setOpaque(false);
setBounds(bounds);
}
};
addMouseListener(mouseHandler);
}
}