Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-24-2007, 11:27 PM
Member
 
Join Date: Jul 2007
Posts: 2
bdn1404 is on a distinguished road
Edit JPanel Text During Runtime...from another class
I am very new to Java and am having trouble changing text at runtime in a JLabel. My main class is set up to handle the computation and displays the UI frame when necessary. I am reading in data real-time so i need to be able to constantly change the label in my frame as the data changes.

I have been testing to see if I could make the runtime changes by putting the code directly into the UIFrame's main. I created the label using the Netbeans design editor and then used this code:

Code:
JLabel jLabel1 = null; jLabel1.setText("text");
which gave me no errors, but had no effect on the label. How do I link my code-created instance with the Netbeans-created label?

Then, if I can get that to work, how do I access that same label from my (seperate) Main class?

Thanks

Last edited by bdn1404 : 07-24-2007 at 11:30 PM. Reason: Typo
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-25-2007, 03:44 AM
Member
 
Join Date: Jul 2007
Posts: 40
elizabeth is on a distinguished road
Write this
Code:
JLabel jLabel1= new JLabel("text");
instead of

Code:
JLabel jLabel1 = null; jLabel1.setText("text");
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-25-2007, 08:01 PM
Member
 
Join Date: Jul 2007
Posts: 2
bdn1404 is on a distinguished road
I have tried that as well. It seems that my frame is not changing anything at runtime. I have tried repainting it, but nothing will change unless I get an event involved.

When I used a button click event as a test, I was able to use the same jPanel1 that I created in Netbeans, because of the nonstatic context. However, when I try to do the same in a main, I have to create an instance which isn't changing.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-10-2007, 03:07 PM
Member
 
Join Date: Jul 2007
Posts: 51
mary is on a distinguished road
please send me the complete code to test it in my machine
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-10-2007, 03:25 PM
Member
 
Join Date: Aug 2007
Posts: 9
rhobincu is on a distinguished road
Quote:
Originally Posted by bdn1404 View Post

Code:
JLabel jLabel1 = null; jLabel1.setText("text");
Check the console. This will most surely generate a NullPointerException.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 08-11-2007, 04:14 AM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
Maybe im wrong, but this is what i get in mind
Quote:
Originally Posted by bdn1404
need to be able to constantly change the label in my frame as the data changes.
Why don't u use a function with a String variable parameter to replace "text" in that class ur working on so that it that can be called from ur main class, maybe like this
Code:
JLabel jLabel1 = new JLabel(initialValue); setLabel(String input) { jLabel1= new JLabel(input); }
And yes, u better post the code
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Example of RunTime class Java Tip Java Tips 0 01-04-2008 10:32 AM
Referencing JPanel Class uncopywritable New To Java 2 08-12-2007 02:31 PM
how to edit lines. jason27131 New To Java 1 08-01-2007 05:41 AM
How To Edit/Add JSP Pages in NetBeans IDE JavaForums NetBeans 0 07-31-2007 12:13 AM
How To:Use a JSlider to adjust Text size in a JPanel louiebagz AWT / Swing 2 07-01-2007 08:37 AM


All times are GMT +3. The time now is 09:44 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org