Bold font called

I tried to do

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

But that does not make him bold. He just looked spaced.

Is this the wrong way?

+3
source share
4 answers

You mark the question as accepted, but the comment says that it does not work. I would agree that it should not work.

Font.BOLD

not a font. This is a font property. If you want to change the font you can make:

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

I added italics just to show you that the code works, as it seems to me that Metal LAF is used by default for bold type.

+7
source

Set the font when creating the border. Sort of:

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

, .

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

TitledBorder , → >

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

TitledBorder , , -, .

: - title - , titleJustification - titlePosition - titleFont -

:

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

TitledBorder , , -, , - .

: - title - , titleJustification - titlePosition - titleFont - titleColor -

+1

createTitledBorder :

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

: border - Border, title - , titleJustification - , - :

 TitledBorder.LEFT 
TitledBorder.CENTER 

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

titlePosition - an integer defining the vertical position of the text relative 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 that defines the font of the title titleColor - a Color object that indicates the color of the title

Returns: TitledBorder object

+1
source

Source: https://habr.com/ru/post/1788635/


All Articles