Solved

Java label title change

Posted on 2014-02-11
8
293 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
  • 4
  • 4
8 Comments
 
LVL 35

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 35

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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 35

Accepted Solution

by:
mccarl earned 500 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 35

Expert Comment

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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
network + 7 73
pairstar challenge 2 42
Requested array size exceeds VM limit 3 51
Strange loading of website behaviour 3 23
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now