?
Solved

Java label title change

Posted on 2014-02-11
8
Medium Priority
?
305 Views
Last Modified: 2014-02-16
I am using netbeans and have set up a label with a title border.  I would like to change the title now and again as the program executes.  Can anyone give me an example as to how to accomplish that.  Thanks.
0
Comment
Question by:sargent240
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 36

Expert Comment

by:mccarl
ID: 39852413
TitledBorder.setTitle(String newTitle);

would be the method that you need to use. However I can't be much more specific without seeing your code. If the above is not for you to solve your issue, can you post your code?
0
 

Author Comment

by:sargent240
ID: 39853498
mccarl, I have an existing label with a title that I created using Netbeans.  Now I want to change the title from within the program.  I tried:

    TitledBorder titled = new TitledBorder("Title");
    jLabel_fouls.setBorder(titled);

Didn't work.  I don't know what code I can provide as the label was originally created by Netbeans.
0
 
LVL 36

Expert Comment

by:mccarl
ID: 39854843
Ok, what I am not understanding though is in your original question you mention that you have a label AND a title border. But a title border can display a title without the need to use a separate label. So I don't understand what you are trying to change the label or the title border (or something else).

As for the code that I referred to, yes you originally create the UI with Netbeans but it actually generates code for you to make that happen. It may roll that code up for you so you don't normally see it, but you can usually click on a + in the margin of your code to see what it has generated. That is the code that may help me to help you (as it will show what objects have been created for the UI and their names, etc)
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:sargent240
ID: 39855055
I'll see what I can gather up for code.  In the mean time.  I have created a label using Netbeans and when I originally created it I set the border to be a title border and it has a title.  The label is what I use to put the foul count for a basketball team on a scoreboard program I have written.  I would like to add an option to change some label titles so it can be used as a wrestling scoreboard.  The border title on the label is "Fouls" when the program executes and if the operator executes a button labeled "wrestling" I would like to change the word "Fouls" to "Match."  When I created the original label I simply drug a label onto a panel, I put "0" on the label and changed the variable name to jLabel_homeFouls, and finally went to the properties of jLabel_homeFouls and set the border to titled making the title name "Fouls."   I hope this helps.
0
 
LVL 36

Accepted Solution

by:
mccarl earned 2000 total points
ID: 39855179
Ok, I think I understand a bit clearer about what is going on. Try this...
((TitledBorder) jLabel_homeFouls.getBorder()).setTitle("Match");

Open in new window

0
 

Author Comment

by:sargent240
ID: 39855262
Perfect my friend.  Thanks!!
0
 

Author Closing Comment

by:sargent240
ID: 39855263
The best!
0
 
LVL 36

Expert Comment

by:mccarl
ID: 39863697
Glad to help! :) (And thanks for the kind comments too!)
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question