Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2005

Tip: Looking for answers? Try searching our database.

GUI freezes after I change contentPane in an ActionListener

Thread view: 
Gioele Barabucci - 27 Jan 2005 12:23 GMT
Hi,

my GUI freezes if I try to replace a contentPane of a JFrame from the
actionListener of one of the components in the current contentPane.
I'd like to change the contentPane after a button as been clicked, but the
button remain pressed and the gui freezes.

class Interface() implements Runnable {
 JFrame frame;

 Interface() {
   frame = new JFrame("Hello");
 }

 void run() {  // the method called from SwingUtilities.invokeLater()
   frame.setContentPane(new MyPanel1(this));
   frame.setVisible(true);
 }

 void doSomeWork() {
   /* callback function: change panel */
   frame.setContentPane(new MyPanel2(this));
 }
}

class MyPanel extends JPanel {

 Interface iface;  // hook for the interface

 MyPanel(Iterface iface) {
   this.iface = iface;

   JButton b = new JButton("Hi");
   b.addActionListener(new ActionListener() {
     void actionPerformed(ActionEvent e) {
       iface.doSomeWork();  // callback to the interface
     }
   });

   this.add(b);
 }
}
Nigel Wade - 28 Jan 2005 10:02 GMT
> Hi,
>
> my GUI freezes if I try to replace a contentPane of a JFrame from the
> actionListener of one of the components in the current contentPane.
> I'd like to change the contentPane after a button as been clicked, but the
> button remain pressed and the gui freezes.

Are you sure it's "frozen"? My immediate guess would be that you've created
an infinite loop - the actionListener changes the componentPane, which
triggers the actionListener, which changes the componentPane...

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.