2011-01-29 16 views
3

は私が太字TitledBorderの

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

をやってみました。しかし、それは大胆作っていません。それはちょうど離れて見えた。

これは間違った方法ですか?

答えて

7

あなたは問題は受け入れられたとマークしますが、コメントには機能しないと表示されます。私はそれが動作してはならないことに同意するでしょう。

Font.BOLD 

はフォントではありません。これはFontのプロパティです。あなたは、フォントを変更したい場合は、行うことができます。

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

は、私はちょうど金属LAFのデフォルトは太字フォントのためであるように私には見えるので、コードは、作品をお見せするためにイタリックを追加しました。

+0

+1興味深いことに、Metalのボールドフォントの使用を明示的にオフにするL&Fデモがあります。 http://download.oracle.com/javase/tutorial/uiswing/examples/components/FileChooserDemo2Project/src/components/FileChooserDemo2.java – trashgod

+1

ご回答ありがとうございます。 =)私はそれを動作させるために別のフォントを使用しました: UIManager.put( "TitledBorder.font"、new Font( "Tahoma"、Font.BOLD、11)); – Kyle

3

境界線を作成するときにフォントを設定します。次のようなものがあります。

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

実際には機能しません。 :| – Kyle

1

あなたは、コードの変更フォントまたはフォントサイズを試してみてください。

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

TitledBorderのは、指定されたボーダー、タイトル、タイトルの位置揃え、タイトルの配置、およびタイトルで、TitledBorderのインスタンスを生成します

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

>>>フォントを指定することができますコンストラクタを持っているようです-フォント。

パラメータ: ボーダー - ボーダー タイトル - ボーダーが titleJustificationを表示すべきタイトル - タイトル titleFontのための位置 - - タイトル titlePositionのための正当化タイトル

をレンダリングするためのフォントと色:

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

は、指定されたボーダー、タイトル、タイトルの位置揃え、タイトルの配置、タイトルのフォント、およびタイトルのカラーで、TitledBorderのインスタンスを作成します。

パラメータ: ボーダー - ボーダー タイトル - ボーダーが titleJustificationを表示すべきタイトル - タイトル titlePositionを正当化する理由 - タイトル titleFontのための位置 - タイトル titleColorのフォント - の色タイトル

1

さえcreateTitledBorderがあります

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

パラメータ: 国境を - タイトルを追加するBorderオブジェクトを

TitledBorder.LEFT 
TitledBorder.CENTER 

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

titlePosition - 関連のテキストの垂直位置を指定する整数: - タイトルの位置揃えを指定する整数 - 次のいずれかのタイトル titleJustificationのテキストを含む文字列 - タイトルに国境に - 以下のいずれか: '

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を指定するフォントオブジェクト - タイトル色

を指定するColorオブジェクト

戻り値: TitledBorderオブジェクト