السلام عليكم ورحمة الله وبركاته....
كيف يمكن اظهار النص كارتباط في العنصر jEditorPane اي يمكن النقر على هذا النص
ارجو المساعدة وشكرا مسبقا.
السلام عليكم ورحمة الله وبركاته....
كيف يمكن اظهار النص كارتباط في العنصر jEditorPane اي يمكن النقر على هذا النص
ارجو المساعدة وشكرا مسبقا.
مقالة مفيدة جدا ![]()
------------------------------
استعمل الطريقة addHyperlinkListener. هناك شرط لكي تعمل، وهو أن ال JEditorPane يجب ألا يكون editable
مثال
import java.awt.Desktop;
import java.io.IOException;
import java.net.URISyntaxException;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLEditorKit;
public class NewClass1 {
public static void main(String[] args) {
JEditorPane editorPane = new JEditorPane();
editorPane.setEditable(false);
editorPane.setEditorKit(new HTMLEditorKit());
editorPane.setText("<html><a href=\"http://www.google.com\">google</a></html>");
editorPane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
System.out.println(e.getURL());
Desktop.getDesktop().browse(e.getURL().toURI());
} catch (URISyntaxException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
});
JFrame frm = new JFrame();
frm.add(editorPane);
frm.setSize(600, 400);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setVisible(true);
}
}شكرا جزيلا اخ herch على الرد السريع والمفيد ....على تقرير :)
المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية
جارٍ التحقق من المتواجدين…