I
Inertia_sublimation
Hehe, yup, its me again, Im still having problems with my GUI, I hope you
guys dont mind my probobly insanely stupid questions. :blush:
Well, Ive followed all the advice in the thread I posted earlier ("GUI
Newb... Im not sure how to make this work. (Auto-scrollbars using a
JTextArea")
And rewrote the NetBeans auto-generated source by hand, it turned out quite
a bit more readable.
Here's the snippet I'm having trouble with:
private JDialog getWaitDialog()
{
/* Init local variables */
final JDialog waitDialog;
final JProgressBar waitBar;
final JLabel waitLabel;
final GridBagConstraints gridBagConstraints;
waitDialog = new JDialog();
waitBar = new JProgressBar();
waitLabel = new JLabel("Please wait...");
gridBagConstraints = new GridBagConstraints();
/* Set values on components: */
waitDialog.setTitle("Processing...");
waitDialog.setResizable(false);
waitDialog.setCursor(new
java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
waitDialog.setLocationRelativeTo(null);
waitBar.setIndeterminate(true);
/* Add components to window */
waitDialog.getContentPane().add(waitLabel);
waitDialog.getContentPane().add(waitBar);
/*Add components to waitDialog */
waitDialog.getContentPane().setLayout(new java.awt.GridBagLayout());
/* Add the progressBar. */
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
waitDialog.getContentPane().add(waitBar, gridBagConstraints);
/* Add the label. */
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
waitDialog.getContentPane().add(waitLabel, gridBagConstraints);
waitDialog.pack();
return waitDialog;
}
/End snippet
You see, this method returns a JDialog containing a JLabel and JProgressBar.
It's supposed to be drawing the JProgressBar while a (possibly) extensive
process is running. After the process has completed its task, the program
setVisible(false) and discard()'s the JDialog, and opens a new window with
the result.
The problem is, is that when the method that calls getWaitDialog() runs, and
show()'s the dialog, all I get is a grey box, no label or progress bar,
until the task is completed (then it dissappears, like its supposed to).
Now... why does the dialog refuse to paint its components?
Here's the method that calls getWaitDialog():
public void mousePressed(MouseEvent evt)
{
/* Display the waitDialog */
final JDialog waitDialog = getWaitDialog();
waitDialog.show();
/* Run long process */
final JFrame resultWindow =
getResultWindow(parser.parseCode(codeTextArea.getText()));
/* Kill the waitDialog */
waitDialog.setVisible(false);
waitDialog.dispose();
/* Display process result */
resultWindow.show();
}
The JDialog *still* doesnt paint even if I have a Thread.sleep() in between
the waitDialog().show; and the resultWindow initilization.
guys dont mind my probobly insanely stupid questions. :blush:
Well, Ive followed all the advice in the thread I posted earlier ("GUI
Newb... Im not sure how to make this work. (Auto-scrollbars using a
JTextArea")
And rewrote the NetBeans auto-generated source by hand, it turned out quite
a bit more readable.
Here's the snippet I'm having trouble with:
private JDialog getWaitDialog()
{
/* Init local variables */
final JDialog waitDialog;
final JProgressBar waitBar;
final JLabel waitLabel;
final GridBagConstraints gridBagConstraints;
waitDialog = new JDialog();
waitBar = new JProgressBar();
waitLabel = new JLabel("Please wait...");
gridBagConstraints = new GridBagConstraints();
/* Set values on components: */
waitDialog.setTitle("Processing...");
waitDialog.setResizable(false);
waitDialog.setCursor(new
java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
waitDialog.setLocationRelativeTo(null);
waitBar.setIndeterminate(true);
/* Add components to window */
waitDialog.getContentPane().add(waitLabel);
waitDialog.getContentPane().add(waitBar);
/*Add components to waitDialog */
waitDialog.getContentPane().setLayout(new java.awt.GridBagLayout());
/* Add the progressBar. */
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
waitDialog.getContentPane().add(waitBar, gridBagConstraints);
/* Add the label. */
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
waitDialog.getContentPane().add(waitLabel, gridBagConstraints);
waitDialog.pack();
return waitDialog;
}
/End snippet
You see, this method returns a JDialog containing a JLabel and JProgressBar.
It's supposed to be drawing the JProgressBar while a (possibly) extensive
process is running. After the process has completed its task, the program
setVisible(false) and discard()'s the JDialog, and opens a new window with
the result.
The problem is, is that when the method that calls getWaitDialog() runs, and
show()'s the dialog, all I get is a grey box, no label or progress bar,
until the task is completed (then it dissappears, like its supposed to).
Now... why does the dialog refuse to paint its components?
Here's the method that calls getWaitDialog():
public void mousePressed(MouseEvent evt)
{
/* Display the waitDialog */
final JDialog waitDialog = getWaitDialog();
waitDialog.show();
/* Run long process */
final JFrame resultWindow =
getResultWindow(parser.parseCode(codeTextArea.getText()));
/* Kill the waitDialog */
waitDialog.setVisible(false);
waitDialog.dispose();
/* Display process result */
resultWindow.show();
}
The JDialog *still* doesnt paint even if I have a Thread.sleep() in between
the waitDialog().show; and the resultWindow initilization.