0

我正在尝试制作边界,这很成功。我希望在边框开始之前有一些间距。现在使用这段代码,文本框周围的边框非常紧。这就是我想做的:理想

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

1 回答 1

3

尝试使用线条边框和空边框创建复合边框:

BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black),
                                   BorderFactory.createEmptyBorder(5, 5, 5, 5))
于 2013-06-12T23:17:41.963 回答