> I've made a resizable JWindow class for some of my GUI needs and I'm
> facing problem with flicker during the resize
[...]
Here's simple example using JFrame instead (see some description at the
bottom) one may try with:
-----TestFrame.java
//package ;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestFrame extends JFrame {
TestFrame() {
super("Test Frame");
setName("MainFrame");
setDefaultCloseOperation(EXIT_ON_CLOSE);
initUI();
}
private void initUI() {
initMenuBar();
Container contentPane = getContentPane();
JDesktopPane workspace = new JDesktopPane();
contentPane.add(workspace, BorderLayout.CENTER);
JInternalFrame iframe = new JInternalFrame("Something",
true, true, true, true);
iframe.setBounds(40, 40, 240, 180);
iframe.setVisible(true);
workspace.add(iframe);
iframe = new JInternalFrame("Other thing",
true, true, true, true);
iframe.setBounds(10, 10, 240, 180);
iframe.setVisible(true);
workspace.add(iframe);
}
private void initMenuBar() {
JMenuBar menuBar = new JMenuBar();
JMenu toolsMenu = menuBar.add(new JMenu("Tools"));
toolsMenu.setMnemonic(KeyEvent.VK_O);
toolsMenu.add(new AbstractAction("Exit") {
{
putValue(MNEMONIC_KEY,
Integer.valueOf(KeyEvent.VK_X));
putValue(ACCELERATOR_KEY,
KeyStroke.getKeyStroke(KeyEvent.VK_Q,
InputEvent.CTRL_DOWN_MASK));
}
public void actionPerformed(ActionEvent evt) {
exit();
}
});
setJMenuBar(menuBar);
}
public void exit() {
System.exit(0);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
initAndShowUI();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
}
static void initAndShowUI() {
//try {
// UIManager.setLookAndFeel(UIManager
// .getSystemLookAndFeelClassName());
//} catch (Exception ex) {
// ex.printStackTrace(); // continue though
//}
//Toolkit.getDefaultToolkit().setDynamicLayout(true);
JFrame.setDefaultLookAndFeelDecorated(true);
Window mainWindow = new TestFrame();
mainWindow.setSize(480, 360);
mainWindow.setLocationRelativeTo(null); // center on screen
mainWindow.setVisible(true);
}
}
-----TestFrame.java--
This example is what I'm trying to accomplish with a JWindow which
doesn't provide a native decoration and controller for resizing the
window. Using the Metal L&F, the native frame decoration is replaced
with a decoration implemented by the L&F for the frame's rootPane - the
flicker during resizing is apparent. The difference should be sizing
events don't come from the native system but from within Swing.
I've tried commenting out:
//JFrame.setDefaultLookAndFeelDecorated(true);
and setting:
Toolkit.getDefaultToolkit().setDynamicLayout(true);
where during resizing, painting events are emitted pretty often, I
guess - no flickering is visible whatsoever.

Signature
Stanimir
Stanimir Stamenkov - 05 Mar 2006 14:52 GMT
> -----TestFrame.java
[...]
> private void initUI() {
> initMenuBar();
[quoted text clipped - 15 lines]
> workspace.add(iframe);
> }
[...]
> -----TestFrame.java--
For a more robust example one may try replacing the JDesktopPane with a
text component inside a JScrollPane so the entire text will be reflowed
and redrawn during a resize:
private void initUI() {
initMenuBar();
Container contentPane = getContentPane();
JTextPane textPane = new JTextPane();
try {
textPane.setPage(new URL("http://www.w3.org/TR/html4/"));
textPane.setEditable(false);
} catch (IOException ioex) {
ioex.printStackTrace();
}
JScrollPane scrollPane = new JScrollPane(textPane);
contentPane.add(scrollPane, BorderLayout.CENTER);
}
> I've tried commenting out:
>
[quoted text clipped - 6 lines]
> where during resizing, painting events are emitted pretty often, I
> guess - no flickering is visible whatsoever.

Signature
Stanimir
Stanimir Stamenkov - 09 Mar 2006 21:44 GMT
>> I've made a resizable JWindow class for some of my GUI needs and I'm
>> facing problem with flicker during the resize
[quoted text clipped - 4 lines]
>
> -----TestFrame.java
[...]
Have somebody tried the example and does everybody experience the
flicker? I've found there's no flicker on 2 of around 10 systems I've
tried with and now wonder what's the cause even more.

Signature
Stanimir