经过大量的努力,我的点击工作正常。可悲的是,当我更改我的格式JTextPane
并将"text/html"
文本添加到 JTextPane 时,我的按钮消失了。我几乎完成了这个苛刻的情妇。有人可以帮忙吗?
代码如下...
import java.awt.*;
import javax.swing.*;
import java.awt.Color;
import javax.swing.JTextPane;
import javax.swing.JButton;
import java.applet.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class jlabeltest extends Applet {
public void init() {
jlabeltest textPaneExample = new jlabeltest();
textPaneExample.setSize(550, 300);
textPaneExample.setVisible(true);
}
public jlabeltest() {
JTextPane textPane = new JTextPane();
textPane.setContentType("text/html");
InlineB button = new InlineB("Button");
textPane.setText("<p color='#FF0000'>Cool!</p>");
button.setAlignmentY(0.85f);
button.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
JOptionPane.showMessageDialog(null,"Hello!");
// Right Click
}
if (SwingUtilities.isLeftMouseButton(e)) {
JOptionPane.showMessageDialog(null,"Click!");
// Left Click
}
}
});
textPane.insertComponent(button);
this.add(textPane);
}
}