Solved

Java label title change

Posted on 2014-02-11
8
301 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
Technology Partners: 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 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 36

Expert Comment

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

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

690 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