Java programming

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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sargent240Author Commented:
Sorry I missed the lines of code.  They are below.

    Border teamBorder = BorderFactory.createLineBorder(, Font.BOLD);
    jLabel_visitorsScore.setBorder(BorderFactory.createTitledBorder(teamBorder,    arguments[1]));
try this,

TitledBorder titledBorder = BorderFactory.createTitledBorder(teamBorder,    arguments[1]) ;
titledBorder.setFont( new Font( "Verdana", Font.BOLD, 12 ) )
and ofcourse you need toi set the border to the label,

jLabel_visitorsScore.setBorder( titledBorder  ) ;
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
sargent240Author Commented:
Thanks all for your information.  It is all helpful to use who are learning the language.
sargent240Author Commented:
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!
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Your welcome! :)     (And a Happy New Year to you too!)
did you try my code?
sargent240Author Commented:
ksivananth - Yes I did try your code and I got an error:

cannot find symbol method setFont(Font)

I appreciate your input.
mccarlIT Business Systems Analyst / Software DeveloperCommented:
I believe .setTitleFont() would be the method you would need to do it that way.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.