I've Googled around and could not find an answer:
I have a JFrame as a GUI and set a componentListener like
this.addComponentListener(new CL(this, logger));
In the componentListener I have the componentResized, etc...
public void componentResized(ComponentEvent e) {
if (e.getSource() == gui) {
here I do the code
}
}
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
I tried some alternatives from StackOverflow in the way of coding, but no way to make it work.
When I minimize the GUI window and restore it, then "componentResized" is being called.
Anyone an idea what's going on and why it works under Java 6 and not Java 7.
Here is a sample 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;
}
}
And this is the startup class:
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);
}
}
When run under Java 6 you get the "Window Resized: Frame" message.
The same run under Java 7, no messages at all.
Below are 2 links to Pictures:
- Java 6
- Java 7
your code (before balast removed, changed to standard) work for me correctly
ComponentListener
firing an event from every pixelsthis is basic property of
componentResized()
, otherwise requiredSwingTimer.restart()
untill resize ended)balast removed, changed to standard