2013-06-12 51 views
0

我試圖製作一個邊框,這是成功的。我希望在邊界開始之前有一段距離。現在使用此代碼,邊框圍繞文本框非常緊密。這就是我想做的事:Ideal在Java中有間距的邊界?

public static void main(String[] args) { 
    // TODO code application logic here 
    //Variables 
    JFrame mainframe = new JFrame(); 
    mainframe.setSize(500, 435); 
    JPanel cards = new JPanel(new CardLayout()); 
    CardLayout cl = (CardLayout)(cards.getLayout()); 
    mainframe.setTitle("Future Retro Gaming Launcher"); 
    //Screen1 
    JPanel screen1 = new JPanel(); 
    JTextPane TextPaneScreen1 = new JTextPane(); 
    TextPaneScreen1.setEditable(false); 
    TextPaneScreen1.setBackground(new java.awt.Color(240, 240, 240)); 
    TextPaneScreen1.setText("Welcome to the install wizard for Professor Phys!\n\nPlease agree to the following terms and click the next button to continue."); 
    TextPaneScreen1.setSize(358, 48); 
    TextPaneScreen1.setLocation(0, 0); 
    TextPaneScreen1.setBorder(BorderFactory.createLineBorder(Color.black)); 
    TextPaneScreen1.setMargin(new Insets(3,3,3,3)); 
    screen1.add(TextPaneScreen1); 
    cards.add(screen1); 
    mainframe.add(cards); 
    mainframe.setVisible(true); 
} 
+0

喜歡的東西,'TextPaneScreen1.setPreferredSize(新尺寸(400,150) );'? –

回答

3

嘗試創建一個compound border伴您行邊框和空邊界:

BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black), 
            BorderFactory.createEmptyBorder(5, 5, 5, 5)) 
+0

我認爲他想以相反的方式使用複合邊界(請參閱他的圖像,線條是邊框的內部部分)。這仍然是正確的,所以+1 – Brian

+0

太棒了!這工作表示感謝。 – Kyle