File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JWindow keeps refreshing or Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JWindow keeps refreshing or "flashing"" Watch "JWindow keeps refreshing or "flashing"" New topic

JWindow keeps refreshing or "flashing"

Mark Siegrist

Joined: Dec 16, 2006
Posts: 1
I am putting together a JTable/TableModel based app but am having trouble with one of the finishing touches that I just assumed would be simple and work : (

When my little app starts the first thing that is visible is a JOptionPane that asks the user for their database username. Then I have another JOptionPane asking for the password, and then a couple of message panes just letting the user know some things. Those all work great but since they are not attached to a parent JFrame I thought it would be a good idea to have a solid-color JWindow to sit behind them, with the popups centered within the JWindow.

Everything appears fine at first until the user clicks on OK (or Cancel) in any of the popups. Once they click on one of those buttons, the JWindow seems to go away and then immediately gets repainted (I'm guessing that's what happens?) - in other words, it "flashes" on and off quickly as the new popup is drawn on the screen.

How do I stop this *very* annoying behavior?

Here is the relevant portion of my code:

public void buildGUI() {
//add a background to house the popups
splashWindow = new JWindow();
splashWindow.setBounds(200, 200, 900, 700);
//ask user for username, and password via popups
dbUsername = JOptionPane .showInputDialog(splashWindow, "Please enter your database username.");
dbPassword = JOptionPane .showInputDialog(splashWindow, "Please enter your database password.");
JOptionPane.showMessageDialog(splashWindow, "Nickie: I'm using the following database/OS: Ubuntu Linux v6.10, MySql database.");
JOptionPane.showMessageDialog(splashWindow, "For this example I have 3 tables in my database: tblPayees, tblTransactions, and tblNotes.");

P.S. I realize that asking the username/password in separate popups (and the password not being asked via a JPasswordField) is not the best way to do it - I do plan on eventually revising that approach.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
for me it flickers only when a button of the first JOptionPane is clicked
java 1.5.0_05, win xp pro, p4 3.2

no flicker on java 1.4.0_01, win98se, celeron 500

don't know why, but if you add an additional setVisible(true), it no longer
flickers for the first JOptionPane

I agree. Here's the link:
subject: JWindow keeps refreshing or "flashing"
It's not a secret anymore!