Hello,
I have a problem with my code and can't see what the difference can be.
I am trying to change my JLabel text via a timer using .setText
I have 2 small apps to demonstrate my problem.
1 - I have a JLabel within a JPanel within a JFrame, and the code below works.
2 - I have a JLabel within a JPanel within a JSplitPane within a JTabbedPane within a JApplet within a JFrame, and the code below does not work.
public void updateMyPanel()
{
m_d += 0.1;
}
double m_d = 0.0;
protected void redrawPanel()
{
if( SwingUtilities.isEventDispatchThread() )
{
label.setText( "" + m_d );
}
else
{
Runnable run = new Runnable()
{
public void run()
{
label.setText( "" + m_d );
}
};
try
{
SwingUtilities.invokeLater(run);
}
catch( InterruptedException ex ) {}
}
}
...
// Tester for JLabel within a JPanel within a JFrame
//
public static void main( String args[] ) throws Exception
{
JFrame oFrame = new JFrame( "Test Panel " );
oFrame.setLayout( new BorderLayout() );
oFrame.setPreferredSize( new Dimension( 200, 200 ) );
oFrame.setVisible( true );
JMyPanel oMyPanel = new JMyPanel();
oFrame.add( oMyPanel, BorderLayout.CENTER );
oFrame.pack();
double d = 0.0;
while( true )
{
Thread.sleep( 1000 );
oMyPanel.updateMyPanel();
}
}
If anyone can someone show me the way, it would be most appreciated.
Thanks, David