title image


Smiley Re: Mmm.
Hier ein funktionierendes Beispiel.

SwingUtilities.invokeLater() nimmt anscheinend den AWT thread. Somit wird die GUI nicht neu gezeichnet. Lösung ein normaler Thread:





import javax.swing.JFrame;

import java.awt.Container;

import javax.swing.JButton;

import java.awt.event.ActionListener;

import javax.swing.JDialog;

import java.awt.event.ActionEvent;

import javax.swing.SwingUtilities;

import javax.swing.JLabel;

import java.awt.FlowLayout;



public class TestGui

extends JFrame implements ActionListener

{

private JDialog jd = null;



public static void main(String args[])

{

JFrame frame = new TestGui();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.show();

}



public TestGui()

{

setTitle("testPleaseWait");

setSize(300, 400);



Container contentPane = getContentPane();

JButton jb = new JButton("Button");

jb.addActionListener(this);



contentPane.add(jb, "Center");

} // constructor



private void callPleaseWait()

{

try

{

int nCount = 0;

for (int n = 0; n < 2000; n++)

{

nCount++;

System.out.print("" + nCount);

Thread.sleep(1);

}

}

catch (Exception ex)

{

ex.printStackTrace();

}

}





public void actionPerformed(ActionEvent e)

{

jd = new JDialog(this, true);

jd.getContentPane().setLayout(new FlowLayout());

jd.getContentPane().add(new JLabel("Please wait..."));

jd.setUndecorated(true);

jd.setBounds(getX() + (getWidth() / 2),

getY() + (getHeight() / 2), 100, 100);



Thread t = new Thread()

{

public void run()

{

callPleaseWait();

jd.dispose();

}

};

t.start();



jd.setVisible(true);

}



}




Gruss,
Christian


geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: