public class EditorPane extends javax.swing.JPanel {
/**
* Creates new form EditorPane
*/
public EditorPane() {
initComponents();
}
private void launchHyperLink(HyperlinkEvent e) {
try {
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
String cmdFileLocation = System.getenv("windir") + File.separator + "system32" + File.separator + "cmd.exe";
Runtime.getRuntime().exec(new String[]{cmdFileLocation, "/c", "start", e.getDescription()});
}
} catch (IOException ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void initEditorPane(JEditorPane editorPane) {
editorPane.setBorder(null);
editorPane.setContentType("text/html");
editorPane.setEditable(false);
editorPane.setOpaque(false);
editorPane.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
launchHyperLink(e);
}
}
});
}
我正在尝试在多个不同的 GUI 中重复使用上述 EditorPane,因为它们具有不同的超链接,它们的行为方式相同。
但我不确定如何initEditorPane
在 GUI 中调用该方法。
这就是我的意思:
public class MainMenu extends javax.swing.JFrame {
private AcademicDTO ac;
public MainMenu(AcademicDTO academicDTO) {
this.ac = academicDTO;
initComponents();
searchTable.init(GUIStaticDataHelper.ACADEMIC_SUMMARY_COLUMNS);
myContactTable.init(GUIStaticDataHelper.CONTACT_SUMMARY_COLUMNS);
initEditorPane(emailTxtComp);
initEditorPane(pageTxtComp);
initComponentsWithData();
initListeners();
}
public void initComponentsWithData() {
nameLabel.setText("" + ac.getTitle() + " " + ac.getForename() + " " + ac.getSurname());
roleLabel.setText(ac.getRole());
roomLabel.setText("Room: " + ac.getRoom());
pageLabel.setText("Page:");
pageTxtComp.setText("<html> <a href='" + ac.getPage() + "'>" + ac.getPage() + "</a> </html>");
hoursLabel.setText("Hours: " + ac.getHours());
phoneLabel.setText("Phone: " + ac.getPhone());
mobileLabel.setText("Mobile: " + ac.getMobile());
emailLabel.setText("Email:");
myContactTable.setData(ac.getContacts());
if (ac.getImage() != null) {
imageLabel.setIcon(new ImageIcon(ac.getImage()));
}
emailTxtComp.setText("<html> <a href='mailto://" + ac.getEmail() + "'>" + ac.getEmail() + "</a> </html> ");
}
emailTxtComp
并且pageTxtComp
现在都是 typeEditorPane
而不是JEditorPane
. 所以这个方法initEditorPane(JEditorPane editorPane)
不能用。
还有线条
initEditorPane(emailTxtComp);
initEditorPane(pageTxtComp);
我要把它们改成什么?