Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Java label title change

Posted on 2014-02-11
8
Medium Priority
?
321 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

824 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