Solved

Java label title change

Posted on 2014-02-11
8
300 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 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

739 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