gpt4 book ai didi

java - JFrame 中的 JPanel 中的 JScrollPane 中的 JTextPane

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:52:37 29 4
gpt4 key购买 nike

我想做的是让 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 中。目前这是它的样子。白色边框是滚动 Pane ,黑色是文本 Pane 。 我想要做的是让边框位于面板的边缘。![][1]

最佳答案

您正在设置面板布局吗?

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

如果您不需要文本框的边框,请执行 textPane.setBorder(null);
不要扩展 JPanel。您可以在创建 JTextPane 时进行创建。

关于java - JFrame 中的 JPanel 中的 JScrollPane 中的 JTextPane,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12470334/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com