开发者

Bold titledBorder

I tried doing

UIManager.getDefaults().put("TitledBorder.font", Font.BOLD);
contentPanel.setBorder(new TitledBorder("Client Downloader"));

But it's not making it bold. It just looked spaced apart.

Is that the wr开发者_运维百科ong way?


You mark the question as accepted, but the comment says its not working. I would agree it should not be working.

Font.BOLD

is not a Font. It is a property of a Font. If you want to change the font you can do:

TitledBorder border = new TitledBorder(...);
border.setTitleFont( border.getTitleFont().deriveFont(Font.BOLD + Font.ITALIC) );

I added the italic just to show you the code works, since it appears to me that in the Metal LAF the default is for a Bold font.


Set the font when you create the border instead. Something like:

 new TitledBorder(new LineBorder(Color.WHITE, 1), "Client Downloader",
                                 TitledBorder.LEFT, TitledBorder.TOP, Font.BOLD);


You can try following code change font or font size what u said in question.

UIManager.getDefaults().put( "TitledBorder.font", new javax.swing.plaf.FontUIResource( new Font( "Arial", Font.BOLD, 12 ) ) ) ;

TitledBorder seems to have a constructor where you can specify the font >>>

public TitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont)

Creates a TitledBorder instance with the specified border, title, title-justification, title-position, and title-font.

Parameters: border - the border title - the title the border should display titleJustification - the justification for the title titlePosition - the position for the title titleFont - the font for rendering the title

And even the color:

public TitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont, Color titleColor)

Creates a TitledBorder instance with the specified border, title, title-justification, title-position, title-font, and title-color.

Parameters: border - the border title - the title the border should display titleJustification - the justification for the title titlePosition - the position for the title titleFont - the font of the title titleColor - the color of the title


Even createTitledBorder has:

public static TitledBorder createTitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont, Color titleColor)

Parameters: border - the Border object to add the title to title - a String containing the text of the title titleJustification - an integer specifying the justification of the title -- one of the following:

 TitledBorder.LEFT 
TitledBorder.CENTER 

TitledBorder.RIGHT 
TitledBorder.LEADING 
TitledBorder.TRAILING 
TitledBorder.DEFAULT_JUSTIFICATION (leading) 

titlePosition - an integer specifying the vertical position of the text in relation to the border -- one of the following: `

TitledBorder.ABOVE_TOP 
TitledBorder.TOP (sitting on the top line) 
TitledBorder.BELOW_TOP 
TitledBorder.ABOVE_BOTTOM 
TitledBorder.BOTTOM (sitting on the bottom line) 
TitledBorder.BELOW_BOTTOM 
TitledBorder.DEFAULT_POSITION (top) 

`titleFont - a Font object specifying the title font titleColor - a Color object specifying the title color

Returns: the TitledBorder object

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜