button6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
StyledDocument doc = (StyledDocument) textPane1.getDocument();
Style style = doc.addStyle("StyleName", null);
StyleConstants.setIcon(style, new ImageIcon("emoticons_01_32.png"));
try {
doc.insertString(doc.getLength(), "ignored text", style);
} catch (BadLocationException e1) {
e1.printStackTrace();
}
}
});
在我的记事本应用程序中,我试图在按钮点击时在JtextPane中添加图像