Java中的间距边框?

时间:2013-06-12 23:05:55

标签: java swing border

我正在尝试制作一个成功的边框。我希望在边界开始之前有一些间距。现在使用此代码,边框在文本框周围非常紧密地包裹。这就是我想要做的事:Ideal

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);
}

1 个答案:

答案 0 :(得分:3)

尝试使用您的行边框和空边框创建compound border

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