많은 고된 작업을 수행 한 후 제 클릭 클릭이 올바르게 작동합니다. 슬프게도, JTextPane
의 형식을 "text/html"
으로 변경하고 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);
}
}
HTML을 사용하지 않고 기본 모드로 유지해야합니까? – Confident
'JTextPane' /'JEditorPane '에 대해 [camickr] (http://stackoverflow.com/users/131872/camickr) 및 [StanislavL] (http://stackoverflow.com/users/301607/stanislavl)의 게시물을 확인하시기 바랍니다. ' – mKorbel
http://java-sl.com/custom_tag_html_kit.html은 버튼 – StanislavL