Ho un problema in cui quando provo ad aggiungere un mouselistener a JLabel o JButton in un JTextPane ottengo l'errore "non può essere convertito a Mouselistener per conversione di invocazione". Preferirei avere il componente in un JEditorPane. Ho anche sentito usare un HyperlinkEvent.Aggiunta di mouselistener a JLabel/JButton inserito in JTextPane
In generale, voglio un componente che può essere premuto a destra/a sinistra in un JEditorPane (preffered)/JTextPane. Qualsiasi aiuto sarebbe gradito
Ora funziona (sortof) riceve solo clic destro e non è necessario disegnare i bordi dei pulsanti. Posso sottolineare il testo del pulsante?
codice di esempio segue ...
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 editorPaneExample = new jlabeltest();
editorPaneExample.setSize(550, 300);
// editorPaneExample.setText("tutorialData.com");
editorPaneExample.setVisible(true);
}
public jlabeltest() {
JTextPane editorPane = new JTextPane();
editorPane.setSelectedTextColor(Color.red);
editorPane.setText("<p color='#FF0000'>Cool!</p>");
InlineB label = new InlineB("JLabel");
label.setAlignmentY(0.85f);
label.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e)
{
if (e.isPopupTrigger())
{
JOptionPane.showMessageDialog(null,"Hello!");
// do your work here
}
}
});
editorPane.insertComponent(label);
this.add(editorPane);
}
}
InlineB.java
import javax.swing.JButton;
public class InlineB extends JButton {
public InlineB(String caption) {
super(caption);
}
}
Hai qualche codice di esempio? – MadProgrammer