import java.awt.event.*;
import javax.swing.*;
public class HtmlTest {
static JFrame frame;
static JEditorPane html;
static JPopupMenu popMenu;
public static void main(String args[]) {
popMenu = new JPopupMenu();
popMenu.add("コピー").addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
String copy = html.getSelectedText();
System.out.println("コピー:"+copy);
}
});
html = new JEditorPane("text/html","");
html.setText("あああ<br>いいい<br>ううう<br>");
html.addMouseListener(new java.awt.event.MouseListener() {
public void mouseClicked(MouseEvent m) {}
public void mouseEntered(MouseEvent m) {}
public void mouseExited(MouseEvent m) {}
public void mousePressed(MouseEvent m) {
if (m.isPopupTrigger()) {
popMenu.show(m.getComponent(), m.getX(), m.getY());
}
}
public void mouseReleased(MouseEvent m) {
if (m.isPopupTrigger()) {
popMenu.show(m.getComponent(), m.getX(), m.getY());
}
}
});
frame = new JFrame("HtmlTest");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(html);
frame.setSize(300,300);
frame.setVisible(true);
}
}
|