繁体   English   中英

JTextPane位于JFrame中的JPanel中的JScrollPane中

[英]JTextPane in a JScrollPane in a JPanel in a JFrame

我想要做的就是让JTextPane在JPanel中占用尽可能多的空间。 对于我正在使用的UpdateInfoPanel:

public class UpdateInfoPanel extends JPanel {
private static final long serialVersionUID = 257125249175323679L;

private JTextPane textPane;

public UpdateInfoPanel(){
    textPane = new JTextPane();
    textPane.setBackground(Color.DARK_GRAY);
    textPane.setEditable(false);
    textPane.setMargin(null);
    textPane.setContentType("text/html");
    textPane.setText("<html><body style=\"font: Arial; color: white; padding: 5px; padding-top: 0;\"><h1 style=\"padding-top: 0;\">News</h1></body></html>");
    JScrollPane scrollPane = new JScrollPane(textPane);
    add(scrollPane);
    setBackground(Color.DARK_GRAY);
    textPane.setBorder(BorderFactory.createLineBorder(Color.BLACK));
}
}

对于我的框架,我只需创建一个这样的实例并将其放在BorderLayout.CENTER中。 目前这是它的外观。 白色边框是滚动窗格,黑色是文本窗格。 我想要做的是让边框位于面板的边缘。 ![] [1]

你在设置面板的布局吗?

    setLayout(new BorderLayout());
    add(scrollPane,BorderLayout.CENTER);

如果你不需要textpane的边框做textPane.setBorder(null);
不要扩展JPanel 您可以在创建JTextPane创建。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM