我試着做大膽的TitledBorder
UIManager.getDefaults().put("TitledBorder.font", Font.BOLD);
contentPanel.setBorder(new TitledBorder("Client Downloader"));
但它沒有把它加粗。它看起來分開。
這是錯誤的方式?
我試着做大膽的TitledBorder
UIManager.getDefaults().put("TitledBorder.font", Font.BOLD);
contentPanel.setBorder(new TitledBorder("Client Downloader"));
但它沒有把它加粗。它看起來分開。
這是錯誤的方式?
您將該問題標記爲已接受,但該評論稱其不起作用。我同意它不應該工作。
Font.BOLD
不是字體。它是一個Font的屬性。如果你想改變字體,你可以這樣做:
TitledBorder border = new TitledBorder(...);
border.setTitleFont(border.getTitleFont().deriveFont(Font.BOLD + Font.ITALIC));
我加了斜體只是爲了顯示你的代碼的工作,因爲在我看來,在金屬LAF默認是粗體字。
改爲創建邊框時設置字體。例如:
new TitledBorder(new LineBorder(Color.WHITE, 1), "Client Downloader",
TitledBorder.LEFT, TitledBorder.TOP, Font.BOLD);
這不是真的有效。 :| – Kyle 2011-01-29 04:08:00
你可以嘗試下面的代碼更改字體或字體大小你說的問題。
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實例,標題對齊方式,標題位置和標題-font。
參數: 邊境 - 邊境 標題 - 標題邊框應顯示 titleJustification - 的理由標題 titlePosition - 標題 的位置titleFont - 用於顯示標題的字體
而且更出彩:
public TitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont, Color titleColor)
用指定的邊框,標題,標題對齊方式,標題位置,標題字體和標題顏色創建TitledBorder實例。
參數: 邊境 - 邊境 標題 - 標題邊框應顯示 titleJustification - 的理由標題 titlePosition - 標題 的位置titleFont - 標題 titleColor的字體 - 顏色標題
即使createTitledBorder有:
public static TitledBorder createTitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont, Color titleColor)
參數: 邊界 - Border對象添加標題到標題 - 一個整數,指定的標題的理由 - - 下列之一含有標題 titleJustification的文本的字符串:
TitledBorder.LEFT
TitledBorder.CENTER
TitledBorder.RIGHT
TitledBorder.LEADING
TitledBorder.TRAILING
TitledBorder.DEFAULT_JUSTIFICATION (leading)
titlePosition - 一個整數,指定相對於文本的垂直位置到邊界 - 下列之一: '
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 - 一個字體對象,指定標題字體 titleColor - 一個顏色對象,指定標題顏色
返回: 標題對象
+1有趣的是,一些L&F演示顯式關閉了Metal對粗體字體的使用,例如, http://download.oracle.com/javase/tutorial/uiswing/examples/components/FileChooserDemo2Project/src/components/FileChooserDemo2.java – trashgod 2011-01-29 11:55:28