Note that there are some explanatory texts on larger screens.

plurals
  1. POJava 7 resize a JFrame (my GUI): the componentListener is not getting fired
    primarykey
    data
    text
    <p>I've Googled around and could not find an answer:</p> <p>I have a JFrame as a GUI and set a componentListener like </p> <pre><code>this.addComponentListener(new CL(this, logger)); </code></pre> <p>In the componentListener I have the componentResized, etc...</p> <pre><code>public void componentResized(ComponentEvent e) { if (e.getSource() == gui) { here I do the code } } </code></pre> <p>Everything is working fine under Java 6, but under Java 7, the Jframe is being resized but is not being repainted: the component listener is not getting called</p> <p>I tried some alternatives from StackOverflow in the way of coding, but no way to make it work.</p> <p>When I minimize the GUI window and restore it, then "componentResized" is being called.</p> <p>Anyone an idea what's going on and why it works under Java 6 and not Java 7.</p> <p>Here is a sample code:</p> <pre><code>public class Frame extends JFrame { private JPanel panel; public Frame() { super(); getContentPane().setBounds(new Rectangle(0, 0, 200, 200)); getContentPane().setLayout(null); getContentPane().add(getPanel()); this.addComponentListener(new ComponentListener() { @Override public void componentResized(ComponentEvent e) { System.out.println("Window Resized: Frame");} @Override public void componentMoved(ComponentEvent e) {} @Override public void componentShown(ComponentEvent e) {} @Override public void componentHidden(ComponentEvent e) {}}); this.setSize(200, 200); this.setPreferredSize(new Dimension(200, 200)); this.pack(); } public JPanel getPanel() { if (panel == null) { panel = new JPanel(); panel.setBackground(Color.RED); panel.setBounds(0, 0, 200, 200); panel.setPreferredSize(new Dimension(200, 200)); } return panel; } } </code></pre> <p>And this is the startup class:</p> <pre><code>public class StartUp { public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } Frame app = new Frame(); app.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); app.pack(); app.setVisible(true); } } </code></pre> <p>When run under Java 6 you get the "Window Resized: Frame" message.<br> The same run under Java 7, no messages at all. </p> <p>Below are 2 links to Pictures: </p> <ul> <li>Java 6 </li> </ul> <p><a href="http://magmabrazil.dyndns.org:4443/images/java6.gif" rel="nofollow">Java 6 Frame Image</a></p> <ul> <li>Java 7 </li> </ul> <p><a href="http://magmabrazil.dyndns.org:4443/images/java7.gif" rel="nofollow">Java 7 Frame Image</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    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