Solved

Java programming

Posted on 2014-01-01
11
280 Views
Last Modified: 2014-01-03
Below are a couple of lines of code I would like to use to change the existing title on a label.  It works fine except I would like to be able to control the font size on the title and don't know what to add.  The color. bold, and title value work fine.
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
  • 3
  • 3
  • +1
11 Comments
 

Author Comment

by:sargent240
ID: 39750074
Sorry I missed the lines of code.  They are below.

    Border teamBorder = BorderFactory.createLineBorder(Color.red, Font.BOLD);
    jLabel_visitorsScore.setBorder(BorderFactory.createTitledBorder(teamBorder,    arguments[1]));
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 39750713
try this,

TitledBorder titledBorder = BorderFactory.createTitledBorder(teamBorder,    arguments[1]) ;
titledBorder.setFont( new Font( "Verdana", Font.BOLD, 12 ) )
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 39750714
and ofcourse you need toi set the border to the label,

jLabel_visitorsScore.setBorder( titledBorder  ) ;
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 39750715
The color. bold, and title value work fine.
Firstly, the bold part of that code CAN'T be working fine, because the second parameter to .createLineBorder() is actually the border thickness. It is only because Font.BOLD is an "int" constant and the thickness of the border is specified as an "int", that allows this code still to compile.

So to do all that you are wanting to do try this...
Border teamBorder = BorderFactory.createLineBorder(Color.RED, 1);  // "1" is the thickness of the border
jLabel_visitorsScore.setBorder(BorderFactory.createTitledBorder(teamBorder, arguments[1], TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font(Font.DIALOG, Font.BOLD, 36))); // Where "36" is the point size of the font that you want to use

Open in new window

Note: also you can change that "Font.DIALOG" constant to one of the other logical font constants or to a string that is an actual font name, eg. "Arial", etc
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39751128
It is only because Font.BOLD is an "int" constant and the thickness of the border is specified as an "int", that allows this code still to compile.
That's why type-safe arguments are always preferable. Fortunately Java has enum since 1.5
0
 

Author Closing Comment

by:sargent240
ID: 39753018
Thanks all for your information.  It is all helpful to use who are learning the language.
0
 

Author Comment

by:sargent240
ID: 39753021
mccarl - I used your code as a foundation, made a few changes and it worked like a champ doing what I needed to do.  I made a few adjustments and all is well.  Happy New Year!
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39753034
Your welcome! :)     (And a Happy New Year to you too!)
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 39753187
did you try my code?
0
 

Author Comment

by:sargent240
ID: 39754059
ksivananth - Yes I did try your code and I got an error:

cannot find symbol method setFont(Font)

I appreciate your input.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39755461
I believe .setTitleFont() would be the method you would need to do it that way.
0

Featured Post

Revamp Your Training Process

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
login form jsp example 2 71
CSV file parsing thru Java 13 54
running on tomcat not jboss eap 7.0 3 53
Is there a Google Voice API? 9 70
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.
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