Results 1 to 6 of 6
- 07-24-2007, 10:27 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 2
- Rep Power
- 0
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:
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?Java Code:JLabel jLabel1 = null; jLabel1.setText("text");
Then, if I can get that to work, how do I access that same label from my (seperate) Main class?
ThanksLast edited by bdn1404; 07-24-2007 at 10:30 PM. Reason: Typo
- 07-25-2007, 02:44 AM #2
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
Write this
instead ofJava Code:JLabel jLabel1= new JLabel("text");
Java Code:JLabel jLabel1 = null; jLabel1.setText("text");
- 07-25-2007, 07:01 PM #3
Member
- Join Date
- Jul 2007
- Posts
- 2
- Rep Power
- 0
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.
- 08-10-2007, 02:07 PM #4
Member
- Join Date
- Jul 2007
- Posts
- 51
- Rep Power
- 0
please send me the complete code to test it in my machine
- 08-10-2007, 02:25 PM #5
Member
- Join Date
- Aug 2007
- Posts
- 9
- Rep Power
- 0
- 08-11-2007, 03:14 AM #6
Senior Member
- Join Date
- Jul 2007
- Posts
- 130
- Rep Power
- 0
Maybe im wrong, but this is what i get in mind
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
Originally Posted by bdn1404
And yes, u better post the codeJava Code:JLabel jLabel1 = new JLabel(initialValue); setLabel(String input) { jLabel1= new JLabel(input); }
Similar Threads
-
How To Edit/Add JSP Pages in NetBeans IDE
By JavaForums in forum NetBeansReplies: 2Last Post: 02-17-2009, 11:14 AM -
Example of RunTime class
By Java Tip in forum Java TipReplies: 0Last Post: 01-04-2008, 09:32 AM -
Referencing JPanel Class
By uncopywritable in forum New To JavaReplies: 2Last Post: 08-12-2007, 01:31 PM -
how to edit lines.
By jason27131 in forum New To JavaReplies: 1Last Post: 08-01-2007, 04:41 AM -
How To:Use a JSlider to adjust Text size in a JPanel
By louiebagz in forum AWT / SwingReplies: 2Last Post: 07-01-2007, 07:37 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks