简体   繁体   中英

JTextPane in a JScrollPane in a JPanel in a JFrame

What I am trying to do is make it so the JTextPane takes up as much space as possible in the JPanel. For my UpdateInfoPanel I am using:

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

And for my frame I simply create an instance of this and put it in BorderLayout.CENTER. Currently this is how it looks. White border is the scroll pane, black is the textpane. What I want to do is have the borders be at the edge of the panel. ![][1]

Are you setting layout of your panel?

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

If you dont need the border of textpane do textPane.setBorder(null);
Dont extend the JPanel . You can create is as you create the JTextPane .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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