Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate an inspecting properties window, button driven as a JDialog
    primarykey
    data
    text
    <p>What I asked originally didn't clearly state my question/problem, so I will explain it better. I have a <code>JButton</code> that sets a <code>JDialog</code> to visible. The JDialog has a <code>WindowListener</code> that sets it to NOT visible on the <code>windowDeactivated()</code> event, which is triggered anytime the user clicks outside of the dialog. The button <code>ActionListener</code> checks if the dialog isVisible, hides it if true, shows it if false.</p> <p><code>windowDeactivated()</code> will always trigger whether clicking on the button or not, as long as the user clicks outside the dialog. The problem I'm having is when the user clicks the button to close the dialog. The dialog is closed by the <code>WindowListener</code> and then the <code>ActionListener</code> tries to display it.</p> <p>If <code>windowDeactivated()</code> doesn't <code>setVisible(false)</code>, then the dialog is still open, but behind the parent window. What I'm asking for is how to get access to the location of the click inside <code>windowDeactivated()</code>. If I know that the user clicked on the button and windowDeactivated() can skip hiding the dialog, so that the button's <code>ActionListener</code> will see that it's still visible and hide it.</p> <pre> public PropertiesButton extends JButton { private JDialog theWindow; public PropertiesButton() { theWindow = new JDialog(); theWindow.setUndecorated(true); theWindow.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); theWindow.add(new JMenuCheckBoxItem("Something")); theWindow.addWindowListener(new WindowListener() { // just an example, need to implement other methods public void windowDeactivated(WindowEvent e) { theWindow.setVisible(false); } }); this.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (theWindow.isVisible()) { theWindow.setVisible(false); } else { JButton btn = (JButton)e.getSource(); theWindow.setLocation(btn.getLocationOnScreen.x,btn.getLocationOnScreen.x-50); theWindow.setVisible(true); } } }); theWindow.setVisible(false); } } </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload