Popup doesn't show up
I want to monitor the progress of a time consuming task in java 1.5.
I found class Popup, and wrote the following test. The label doesn't show in the popup, its just empty.
What's wrong?
Btw, I sent a good deal of time searching for examples.
Does anyone know of good, complete code examples with more "perifer" (?) swing classes like Popup?
Or a good book on the subject?
THANKS!
Jonas E.
Here's the code:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class PopupTest
{
public static void main (String [] args)
{
final JFrame f = new JFrame ();
f.setLocation (400, 200);
final JPanel pane = new JPanel (true);
JButton b = new JButton ("Popup");
pane.add (b);
final JTextField label = new JTextField ("a label...");
label.setColumns (20);
label.setBorder (BorderFactory.createTitledBorder ("The field..."));
b.addActionListener (new ActionListener (){
public void actionPerformed (ActionEvent ae){
PopupFactory pf = PopupFactory.getSharedInstance ();
Point p = f.getLocationOnScreen ();
//Et.dis ("point: " + p);
int x = (int) p.getX ();
int y = (int) p.getY ();
Popup pu = pf.getPopup (null, label, x, y);
pu.show ();
for (int i = 0; i < 6; i++){
label.setText ("update " + i);
try {Thread.currentThread ().sleep (500);}
catch (Exception ignore){}
}
pu.hide ();
// to check that label really is "showable"
pane.add (label);
f.pack ();
}
});
f.setContentPane (pane);
f.pack ();
f.setVisible (true);
}
}

