我在JTextPane中添加图片时遇到一个问题:
StyleContext styles = new StyleContext();
DefaultStyledDocument doc = new DefaultStyledDocument(styles);
Style style = styles.addStyle(null, null);
ImageIcon imageIcon = new ImageIcon(fPath.toString());
StyleConstants.setIcon(style, imageIcon);
doc.insertString(insertPos, " ", style);
textPane.setDocument(doc);
我的JTextPane是放在JScrollPane里的,但是当图片大小超过了JTextPane的大小时,水平滚动条怎么也不出现,垂直滚动条倒是正常,我把scrollbar policy设为
AS_NEEDED或ALAWAYS都不管用,请问应该怎么解决,谢谢。
StyleContext styles = new StyleContext();
DefaultStyledDocument doc = new DefaultStyledDocument(styles);
Style style = styles.addStyle(null, null);
ImageIcon imageIcon = new ImageIcon(fPath.toString());
StyleConstants.setIcon(style, imageIcon);
doc.insertString(insertPos, " ", style);
textPane.setDocument(doc);
我的JTextPane是放在JScrollPane里的,但是当图片大小超过了JTextPane的大小时,水平滚动条怎么也不出现,垂直滚动条倒是正常,我把scrollbar policy设为
AS_NEEDED或ALAWAYS都不管用,请问应该怎么解决,谢谢。
构造函数用对了没有
JScrollPane()
创建一个空的(无视口的视图)JScrollPane,需要时水平和垂直滚动条都可显示。
JTextPane textPane= new JTextPane();
...
JScrollPane scrollPane = new JScrollPane(textPane,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
垂直滚动条可以正常出现,但水平滚动条却不出现。
第三个参数用JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS只是在下面出现一个滚动条的槽,
但放入图片时,滚动条却不出现。
查java core去,里面有介绍
要不找一本swing编程来看,也有。