Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - setting Fonts/Color in setBorder

Is there a way I can define my own font and color schemes for Text1 AND Text2 text within the setBorder method. New to java and cannot find it in the SUN tutorials.

My code

//Create Positions Table
 JPanel SpreadPanel = new JPanel();
 SpreadPanel.setBorder(BorderFactory.createTitledBorder(" Text 1    Text 2"));

Regards Simon

like image 506
Simon Avatar asked Feb 02 '23 23:02

Simon


2 Answers

setBorder(BorderFactory.createTitledBorder(null, "text", TitledBorder.CENTER, TitledBorder.BOTTOM, new Font("times new roman",Font.PLAIN,12), Color.yellow));

the first parameter null or another border (for compound borders) 2nd param text that you're displaying 3rd and 4th param justification and location of the text from param 2

4th param and 5th param are the two to set font and color

like image 69
Xiaoerge Avatar answered Feb 05 '23 13:02

Xiaoerge


If you want a different font and color for each of the strings (e.g. Text1 and Text2) in the same TitledBorder, you may be need to extend AbstractBorder and override paintBorder(). The existing implementation only has one font and one color for a single title.

like image 36
trashgod Avatar answered Feb 05 '23 14:02

trashgod