JTextPane adding hyperlinks
Hello everyone. I currently have a simple chat window implemented using a JTextPane. A chat message consists of a star image, timestamp, username, and the message. I am attempting to allow other people in the chat room to click on the username of the message, and obtain additional information about that person. Here's my current code:
public void initAttributeSets()
green = new SimpleAttributeSet();
StyleConstants.setForeground(green, chatColorGreen);
StyleConstants.setBold(green, false);
StyleConstants.setFontSize(green, chatFontSize);
green_bold = new SimpleAttributeSet();
StyleConstants.setForeground(green_bold, chatColorGreen);
StyleConstants.setBold(green_bold, true);
StyleConstants.setFontSize(green_bold, chatFontSize);
public void setLobbyChatMessage(int star, String username, String message)
Document doc = lobbyChatPane.getStyledDocument();
try
// user message, display as green text
StyleConstants.setIcon(starIcon,imageIcons[star-1]);
doc.insertString(doc.getLength(), "star", starIcon);
doc.insertString(doc.getLength(), " [timestamp] " + username + "> ", green_bold);
doc.insertString(doc.getLength(), message + "\n", green);
catch(BadLocationException exp)
// do nothing
lobbyChatPane.setCaretPosition( doc.getLength() );
private SimpleAttributeSet green;
private SimpleAttributeSet green_bold;The hyperlink would not effect the JTextPane window in any way. I wish to implement using hyperlinkUpdate(HyperlinkEvent event) to determine the usename and display information using some kind of Dialog. I have been having a very hard time getting the hyperlink to work with the other components. Any suggestions/solutions would be appreciated, thanks.
Doesn't anyone have a hint for me here?
Similar Messages
-
Insert String to JTextPane as hyperlink
Hi,
I have a JTabbedPane with 2 tabs, on each tab is one panel.
On first pannel I add JTextPane and I would like to insert in this JTextPane some hyperlinks.
I found some examples in forum, but doesn't work for me.
Could somebody help me ?
Thank's.
Here is my code :
JTextPane textPane = new JTextPane();
textPane.setPreferredSize(new Dimension(500,300));
HTMLEditorKit m_kit = new HTMLEditorKit();
textPane.setEditorKit(m_kit);
StyledDocument m_doc = textPane.getStyledDocument();
textPane.setEditable(false); // only then hyperlinks will work
panel1.add( textPane,BorderLayout.CENTER); //add textPane to panel of
//JTabbedPane
String s = new String("http://google.com");
SimpleAttributeSet attr2 = new SimpleAttributeSet();
attr2.addAttribute(StyleConstants.NameAttribute, HTML.Tag.A);
attr2.addAttribute(HTML.Attribute.HREF, s);
try{
m_doc.insertString(m_doc.getLength(), s, attr2);
}catch(Exception excp){};
The String s is displayed like text not like hyperlink..Hi , You can take a look at this code , this code inserts a string into a StyledDocument in a JTextPane as a hyperlink and on clicking fires the URL on the browser.
/* Demonstrating creation of a hyperlink inside a StyledDocument in a JTextPane */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.Border;
import javax.swing.text.*;
public class Hyperlink extends JFrame {
private Container container = getContentPane();
private int toolXPosition;
private int toolYPosition;
private JPanel headingPanel = new JPanel();
private JPanel closingPanel = new JPanel();
private final static String LINK_ATTRIBUTE = "linkact";
private JTextPane textPane;
private StyledDocument doc;
Hyperlink() {
try {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
setSize(300, 200);
Rectangle containerDimension = getBounds();
toolXPosition = (screenDimension.width - containerDimension.width) / 10;
toolYPosition = (screenDimension.height - containerDimension.height) / 15;
setTitle("HYPERLINK TESTER");
setLocation(toolXPosition, toolYPosition);
container.add(BorderLayout.NORTH, headingPanel);
container.add(BorderLayout.SOUTH, closingPanel);
JScrollPane scrollableTextPane;
textPane = new JTextPane();
//for detecting clicks
textPane.addMouseListener(new TextClickListener());
//for detecting motion
textPane.addMouseMotionListener(new TextMotionListener());
textPane.setEditable(false);
scrollableTextPane = new JScrollPane(textPane);
container.add(BorderLayout.CENTER, scrollableTextPane);
container.setVisible(true);
textPane.setText("");
doc = textPane.getStyledDocument();
Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
String url = "http://www.google.com";
//create the style for the hyperlink
Style regularBlue = doc.addStyle("regularBlue", def);
StyleConstants.setForeground(regularBlue, Color.BLUE);
StyleConstants.setUnderline(regularBlue,true);
regularBlue.addAttribute(LINK_ATTRIBUTE,new URLLinkAction(url));
Style bold = doc.addStyle("bold", def);
StyleConstants.setBold(bold, true);
StyleConstants.setForeground(bold, Color.GRAY);
doc.insertString(doc.getLength(), "\nStarting HyperLink Creation in a document\n\n", bold);
doc.insertString(doc.getLength(), "\n",bold);
doc.insertString(doc.getLength(),url,regularBlue);
doc.insertString(doc.getLength(), "\n\n\n", bold);
textPane.setCaretPosition(0);
catch (Exception e) {
public static void main(String[] args) {
Hyperlink hp = new Hyperlink();
hp.setVisible(true);
private class TextClickListener extends MouseAdapter {
public void mouseClicked( MouseEvent e ) {
try{
Element elem = doc.getCharacterElement(textPane.viewToModel(e.getPoint()));
AttributeSet as = elem.getAttributes();
URLLinkAction fla = (URLLinkAction)as.getAttribute(LINK_ATTRIBUTE);
if(fla != null)
fla.execute();
catch(Exception x) {
x.printStackTrace();
private class TextMotionListener extends MouseInputAdapter {
public void mouseMoved(MouseEvent e) {
Element elem = doc.getCharacterElement( textPane.viewToModel(e.getPoint()));
AttributeSet as = elem.getAttributes();
if(StyleConstants.isUnderline(as))
textPane.setCursor(new Cursor(Cursor.HAND_CURSOR));
else
textPane.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
private class URLLinkAction extends AbstractAction{
private String url;
URLLinkAction(String bac)
url=bac;
protected void execute() {
try {
String osName = System.getProperty("os.name").toLowerCase();
Runtime rt = Runtime.getRuntime();
if (osName.indexOf( "win" ) >= 0) {
rt.exec( "rundll32 url.dll,FileProtocolHandler " + url);
else if (osName.indexOf("mac") >= 0) {
rt.exec( "open " + url);
else if (osName.indexOf("ix") >=0 || osName.indexOf("ux") >=0 || osName.indexOf("sun") >=0) {
String[] browsers = {"epiphany", "firefox", "mozilla", "konqueror",
"netscape","opera","links","lynx"};
// Build a command string which looks like "browser1 "url" || browser2 "url" ||..."
StringBuffer cmd = new StringBuffer();
for (int i = 0 ; i < browsers.length ; i++)
cmd.append((i == 0 ? "" : " || " ) + browsers[i] +" \"" + url + "\" ");
rt.exec(new String[] { "sh", "-c", cmd.toString() });
catch (Exception ex)
ex.printStackTrace();
public void actionPerformed(ActionEvent e){
execute();
}Here , what I have done is associated a mouseListener and a mouseMotionListener with the JTextPane and I have created the hyperlink look with a Style of blue color and underline and have added the LINK_ATTRIBUTE to that Style which takes care of listening to mouse clicks and mouse motion.
The browser can be started in windows using the default FileProtocolHandler using rundll32 and in Unix/Sun we have to take a wild guess at which browser could be installed , the first browser encountered is started , in Mac open command takes care of starting the browser.
Hope this is useful. -
Adding Hyperlinks to photos in iWeb
Using a photo template in iWeb, I am having trouble adding hyperlinks to photos as well as to the 'captions' beneath the photos... is adding hyperlinks simply not possible in a photo template or available only on selected templates?
Appreciate any help.Try this old technic:
http://discussions.apple.com/thread.jspa?messageID=4888047� -
Adding hyperlinks to Flash Executable files
I'm using a demo version of Flash 5 to see if I'd like to
invest in a copy of Flash. I added hyperlinked text to to a flash
movie I produced, and when I uploaded the html added to a webpage,
when I click on the hyperlink it successfully takes me to the
correct website. However, when I try clicking on the executable
file version of the same flash movie, published at the same time,
although I get the usual little hand when the put the cursor over
the hyperlink I'm not taken to any webpage.
Can anyone tell me what's going wrong?HI
You need to use FlashJester JStart
http://jstart.flashjester.com
Download a FREE evaluation copy and try it.
Regards
FlashJester Support Team
e. - [email protected]
w. - www.flashjester.com
"This has been one of the most impressive and thoroughly
pleasant
experiences of customer support I have ever come across -
astounding!"
Director - hedgeapple -
Adding hyperlinks to objects in 3D PDF
Hi everyone,
I'm trying to figure out if 3D PDF has the capability to import a number of individual machine models (made in SolidWorks) to create a 3D layout of a facility, and then make it so people viewing this layout can click (or doubleclick) on a machine and have that open a web page (or another .pdf file)...are there javascript routines that get called when one of the objects is clicked/doubleclicked? If so, can that script be used to open up a url?
Any help would be appreciated,
Thanks,
Jon FournierOn second thought, here is the an example code for adding hyperlinks to objects. It will be very tedious to do this for a huge number of parts. If metadata could be stored (no such luck) in the u3d file, this process would be very easy.
- Greg
http://www.immdesign.com
The u3d file and pdf example are available using the links:
http://www.immdesign.com/templates/hyperlink.pdf
http://www.immdesign.com/templates/robotHand.u3d
Parts of the code below were given to me by Grayson Lang.
The code below must be added as a document level javascript
use the menu - Advanced->Javascript->Document Javascript...
// -------- Start of Document Script
initialize3D = function ()
var a3d = getAnnots3D(0)[0];
var c3d = a3d.context3D;
if ( a3d.activated )
app.clearInterval( timeout );
c3d.runtime.doc = this;
c3d.runtime.app = app;
var timeout = app.setInterval( "initialize3D()", 200 );
// -------- End of Document Script
// -------- Start of 3D Script
// Save this code in as a .js file and use it as the default
// script when inserting the u3d file into your PDF file
// ugly code to add hyperlinks on selection of an object
// this will only work with URLs and will not work for
// just openning any old file
// format for the hyperlink array -
// hLinks["the object's name"] = "file URL"
var hLinks = new Array;
hLinks["fingertip-1"] = "http://www.immdesign.com"
hLinks["fingertip-2"] = "http://www.myroombud.com"
hLinks["fingertip-3"] = "http://www.adobe.com"
function onSelection( objName ) {
if ( typeof( hLink = eval( "hLinks['" + objName + "']" ) ) != 'undefined' ) {
if (runtime.app) { runtime.app.launchURL(hLink); }
// ack! we have to create our own "pick" function since there is no way
// to get the selected object from the Acrobat pick right now
var downX = -999999999999;
var downY = -999999999999;
var mouseDown = 0;
myMouseHandler = new MouseEventHandler();
myMouseHandler.onMouseDown = true; //this prop is true by default
myMouseHandler.onMouseUp = true; //this prop is true by default
myMouseHandler.onMouseMove = true;
myMouseHandler.reportAllTargets = false;
myMouseHandler.onEvent = function(event)
// capture mouse down location
if ( event.isMouseDown ) {
downX = event.mouseX
downY = event.mouseY
mouseDown = 1;
else {
// check if mouse up is the same location as mouse down
if ( event.isMouseUp ) {
if ( downX == event.mouseX && downY == event.mouseY ) {
if ( event.hits.length ) {
objName = event.hits[0].target.name;
onSelection( objName );
downX = -999999999999;
downY = -999999999999;
mouseDown = 0;
//Register the handler and turn the mule on
runtime.addEventHandler(myMouseHandler);
// ------ End of 3D Script -
Can anyone help with advise on how to add a hyperlink to text
in Captivate 4. The hyperlinks from PowerPoint seem, to work, but I
can't see a way to add a hyperlink in the text field to an external
website.Hi
Ok I was trying to record it, not working
Make sure that you've copied or saved the pdf files are in the web site folder first
1 insert text,
2 with this text, create a fake link, blue and underline
3 click on Click box in the tools box
4 resize the click box over the fake link, I only keep the hint Type hint here (I deleted the 2 others) and I type Click on the link, in French Cliquez sur le lien
5 click box is still selected, then in the left menu select Action tab
6 In drop-down menu On success select Open url or file
7 Click to browse, click on file or type the url
8 Click on the drop down menu (arrow), click and select New so that way it will opens in a New browser window.
When you export in swf
You will have, at the end of the exportation, to copy paste manually the files in the web folder where is the swf file.
Now we have a new problem. I didn't have this problem with all the projects published, but it happened once. Also, once on the server, the link would not open for that reason, see this blog. Still working on it.
http://sorcererstone.wordpress.com/2009/06/19/when-captivate-links-don t/
sophie
Date: Mon, 6 Sep 2010 19:21:40 -0600
From: [email protected]
To: [email protected]
Subject: Adding hyperlinks to CP4 text
Can someone provide me to the steps of adding hyperlinks
to CP4?
> -
Adding hyperlinks to word report generated using Report Generation Toolkit (RGT)
Hi All,
I am generating a word report using LabVIEW RGT. I would like to add Hyperlinks to the files in the local PC to the word report. I found few links which explain adding hyperlinks to Excel report but not word report.
Please help me with this.
Anandelamaran Duraisamy,
Senior Project Engineer,
Soliton Technologies (P) Ltd,
www.solitontech.com
Solved!
Go to Solution.Hi Srikrishna,
Thanks for your effort to reply. I think you are suggesting it for Excel report.
It seems that we can use the below shown VI to add Hyperlinks to a word report,
I initially thought it will only work for HTML reports.
Anandelamaran Duraisamy,
Senior Project Engineer,
Soliton Technologies (P) Ltd,
www.solitontech.com -
Adding Hyperlinks to other projects (Merged)
I am running into an issue with adding Hyperlinks to other projects. I have several projects that I have merged into one Master project. I have generated all the child projects into their corresponding Merged Project folders in the master file. All I am trying to do is link one project to another. So in "Child Project A" I have a hyperlink to "Child Project B". I am linking to a "File" which is Project B's HTML file in the Master Project (Merged Folder). When I do this, I get a message in project A that:
"This action will create an external link to the help system. The link may not function when the help system is moved to other systems. Create link anyway?"
So I create the link and generate Project A, but when I generate the Master Project, the link does not work. How do I fix this? Links that I have to pages within a project work just fine, but not when linked externally even though all the projects linked have been merged within the Master Project.My link is showing in the HTML like this:
<a href="../../../MasterMerge/mergedProjects/ChildProject2/ChildProject2.htm">test link</a>
Where "MasterMerge" is the name of the folder that I have given to generate the master project to. I was expecting RoboHelp to convert my absolute path to a relative path that looks like this:
<a href="../ChildProject2/ChildProject2.htm">test link</a>
as you suggested. I can't figure out why it is changing my absolute path to a relative path that is so long..and still the link is not working. The work-around for this is that I go into the HTML and just paste in my absolute path. I don't want to continue doing this.
Note that my actual path looks something like this:
Q:\QA\Application Documentation\MasterMerge\mergedProjects\ChildProject2\ChildProject2.htm
Do I have too many folders? If so, I'm not sure what to do about this since my project needs to reside on a specific drive and folder at work that other departments don't have access to.
Thanks for responding! I'm just so frustrated with this because it seems the little details are causing me the most trouble. -
I have several JTextPanes added to a JPanel. I just want the JTextPane that is currently focused shd be painted(visible) fully irrespective of the order in which it is added to the JPanel.
My project is to develope a GUI similler to MS Powerpoint, using Java Swing
Thanks in Advance
anuHey,
Thank u.I solved that pbm.
But one more pbm araise coz of that i think.
Components caret & selected text are not visible.
is it coz of removing & then adding components to JPanel?
I've registered all listeners(Focus etc), when the components obj r created.
It was working before that. ie omitting 3 lines indicated by //new
anu
sample codes from JPanel
public void bringComponentToFront()
if (focused == null)
return;
Vector tmpVector = new Vector();
int compCount = getComponentCount();
// bring component to front by inserting it first into the slide
tmpVector.add((Component)focused);
for(int i=0; i < compCount; i++) {
Component tmpComp = getComponent(i);
if (!tmpComp.equals(focused))
tmpVector.add(tmpComp);
removeAll();
for(int i=0; i < compCount; i++)
add((Component)(tmpVector.elementAt(i)));
repaint();
//before focusing a new component,the current order of components r saved
public void saveOrder()
int compCount = getComponentCount();
tmpVector1.clear();
for(int i=0; i < compCount; i++)
Component tmpComp=getComponent(i);
tmpVector1.add(tmpComp);
//retriving the old order
public void retryOrder()
int compCount = getComponentCount();
removeAll();
for(int i=0; i < tmpVector1.size(); i++)
add((Component)(tmpVector1.elementAt(i)));
repaint();
sample codes from JTextPane
//constructor
addFocusListener(new FocusListener)
public void focusGained(FocusEvent e)
parentSlide.saveOrder(); //new
parentSlide.bringComponentToFront(); //new
if (m_xStart>=0 && m_xFinish>=0)
if (getCaretPosition()==m_xStart)
setCaretPosition(m_xFinish);
moveCaretPosition(m_xStart);
else
select(m_xStart, m_xFinish);
public void focusLost(FocusEvent e)
parentSlide.retryOrder(); //new
m_xStart = getSelectionStart();
m_xFinish = getSelectionEnd();
focused: currently focused Component(JTextPane)
parentSlide : current slide(JPanel) of PowerPoint
tmpVector1: globally declared -
JTextPane: Problem adding hyperlinks & images
Hi,
I have a problem and I just can't figure out how to solve it.
I need to implement a simple Editor for HTML files. Lucky for me, most of the functionality i need is already provided by swing, but i still need to add images and hyperlinks to my document. Especially, i need to be able to select some text, click on a button and turn it into a hyperlink. If an image is within the selected range, then the image should be included in the hyperlink as well (just as you would expect it to be).
Adding images works so far, using this code (i'll take care of actually loading the image when the rest works).
JEditorPane editor = getEditor( e );
HTMLDocument doc = (HTMLDocument) getStyledDocument( editor );
MutableAttributeSet attr = new SimpleAttributeSet();
attr.addAttribute( StyleConstants.NameAttribute, HTML.Tag.IMG );
attr.addAttribute( HTML.Attribute.SRC, "p.gif" );
try {
doc.insertString( editor.getCaretPosition(), " ", attr );
} catch (BadLocationException e1) {
e1.printStackTrace();
}But when i try to do the same with HTML.Tag.A and HTML.Attribute.HREF, the selected text disappears from the code (it is still visible in the JTextPane, though) and is replaced by . I just don't seem to get the whole AttributeSet mechanism or which attributes need to be set to which values.
I have seriously been stuck on this stuff for over one day now, and went through half a million tutorials, but can't figure it out - and i can't imagine that it is that complicated to do something like that.
By the way, I don't care whether or not you can click on the link in the JTextPane. The whole application is just for editing purposes and the document's content will be uploaded to a webserver at a later point.
I hope there's somebody who can help me out here.
Thanks in advance,
ak87Doesn't anyone have a hint for me here?
-
Adding Hyperlinks to text on a Summary Sheet in Powerpoint
Hi
I have a slide show that features No buttons, for questions 1- 10, If a user clicks a No button it prints a row of text with help for that particular topic.
Im using vba to generate the wording and code for the summary page, see below
Code for the No button is below
Sub No1(button As Shape)
If button.Fill.ForeColor.RGB <> RGB(128, 100, 162) Then
button.Fill.ForeColor.RGB = RGB(128, 100, 162)
Else
button.Fill.ForeColor.RGB = RGB(255, 255, 255) ' default white colour
End If
q1Answered = False
If q1Answered = False Then
numIncorrect = numIncorrect + 1
answer1 = "1. Answer to question 1 - Click Here for Further Help" & vbCr 'ADDED
End If
End Sub
Code for the summary page is below
Sub SummarySlide1() 'Summary Page for Create ADDED
Dim printableSlide As Slide
Dim homeButton As Shape
Dim printButton As Shape
Set printableSlide = _
ActivePresentation.Slides.Add(Index:=summarySlideNumber1, _
Layout:=ppLayoutText)
printableSlide.Shapes(1).TextFrame.TextRange.Font.Size = 9
printableSlide.Shapes(1).TextFrame.TextRange.Text = _
vbCr & vbCr & vbCr & userName & _
vbCr & "The following areas have been highlighted as one(s) which need development"
printableSlide.Shapes(2).TextFrame.TextRange.Font.Size = 8.5
printableSlide.Shapes(2).TextFrame.TextRange.Text = _
answer1 & vbCr & answer2 & vbCr & answer3 & vbCr & answer4 & vbCr & answer5 & vbCr & _
answer6 & vbCr & answer7 & vbCr & vbCr & answer8
ActivePresentation.SlideShowWindow.View.GotoSlide 40
MsgBox " Please Remember to Print Your Results before you leave this Page "
ActivePresentation.Saved = True
End Sub
So what you end up with on the summary sheet is all the NO's the user has clicked
for example
1. Answer to question 1 - Click Here for Further Help
What i'd like to do is turn the click here part in this text into a hyperlink to another web page
Is there a way to do this using vba?
Any help would be appreciated
Thanks
JinksHi Jinks,
For this requirement, you could add a textbox with text: Click here, then use
Hyperlink Object to add click action.
With ActivePresentation.Slides(1).Shapes(3) _
.ActionSettings(ppMouseClick)
.Action = ppActionHyperlink
.Hyperlink.Address = "http://www.microsoft.com"
End With
Regards
Starain
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Adding Hyperlinks in Report shuould take action in PDF Output
Hi All,
I had a requirement with reports
Explanation of the requirement.
I had a report aaa.rdf which gives a (one)employee monthly details.
which need to be output in PDF.
now the requuirement is
I had added labels "next-month" and "previous-month" labels at either side of report title.
I need the code to kept in these labels such that when this report is executed and taken into PDF file, when user
user clicks on the "next-month" or "previous-month" in that PDF file, the action to take is it should re-ran the same report(aaa.rdf) and should display the output in PDF in the same window but now the output should show the
coressponding next-month or previous-month results respectively of that employee.
please let me know if this make sense.
please guide for the above requirement.
this is very very urgent your help will be appreciated.
Thanks in advance
RRMHi,
it is not too late ....
It's possible to add such Hyperlinks to the pdf-Output of a report.
With use of the built-in rw.set_hyperlink('hyperlink') in a format trigge you can realize that. "hyperlink" is for example then something like:
'/reports/rwservlet?destype=cache&desformat=pdf&report=drilldetail.jsp&userid=scott/tiger@josi&p_deptno='||:deptno
In your case it's a call to the same report you run before and you had to set your month-parameter in the call depending your current month (next or previous).
With srw.set_hyperlink_attrs('string') it's possible to add additional attributes like for example
srw.set_hyperlink_attrs('target=_new')
which opens a new browser window.
This works for HTML & PDF.
Regards
Rainer -
Adding Hyperlink to Video Made in Final Cut Pro
I created a 10 second which incorporates my logo flash by the screen and concludes with a fade in of two different banners:
one leading to a commercial side of my work and another leading to personal.
I want to somehow export this video and import it into ActionScript and place a distinguished hyperlink over each banner. Any suggestions my genius Adobe Family?
Someone's got it en the bag! Hey, I appreciate any help I can get -NickThanks for the terminology. Yes I guess it is banding on my BRD and it displays the proper gradient when I play directly out from FCP. Sequence preset is DV NTSC 48 kHz. Capture Preset is DVCPRO HD - 1080i60 48 kHz. I let FCP select the settings when I brought in my 1st bit of HD video from my camera (via IMovie: I couldn't find a way to get in directly). My video is from the new Sony NEX (1080i). I'm sorry if I didn't answer your question re: format. I'm not very techy. I didn't understand "like noise added or in 10-bit." Thanks for your help!
-
Hi,
I?m building a little IRC client. I?m using a swing JtextPane but my problem is that I can?t insert hyperlinks into it.
The JtextPane is based on a DefaultStyledDocument, I have created a Style called Hyperlink.
Style style4 = myStylePane.addStyle("Hyperlink", defstyle);
StyleConstants.setUnderline(style4,true);
doc.insertString(doc.getLength(),"Http://www.Java.Sun.com",style4);
The problem is that I can?t find a proper method how I can make the text a click-able hyperlink.
I have tried already the following:
Style style4 = myStylePane.addStyle("Hyperlink-Jlabel", defstyle);
StyleConstants.setComponent(style4, new Jurl("http://www.Java.sun.com"))
doc.insertString(doc.getLength(),"Ignore text",style4);
The class Jurl extends of Jlabel, plus I have implemented the event mouseclicked that opens the url in a blank browser window.
But the problem here is that Jlabel breaks out of the visible rectangle of my JtextPane (right side break). So it is possible that I see for example http://www.Java.su here ends my JtextPane. The JtextPane does no take a new line to display the JLabel.
Thanks in advance and,
Have a nice day.
Pieter PareitHere, you should be able to adapt this;-import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.applet.*;
public class linkIt extends Applet {
Panel back = new Panel();
public linkIt(){
super();
setLayout(new BorderLayout());
add("Center",back);
back.setLayout(null);
Olink link1 = new Olink(this,"Go to google and search ","http://www.google.com");
back.add(link1);
link1.setBounds(10,10,100,25);
Olink link2 = new Olink(this,"Answer for programmers ","http://forum.java.sun.com");
back.add(link2);
link2.setBounds(10,40,100,25);
public void init(){
setVisible(true);
public class Olink extends Label implements MouseListener {
Applet applet;
Color fcolor = Color.blue;
Color lcolor = Color.magenta;
String text;
String wadd;
public Olink(Applet ap, String s, String s1){
super(s);
this.applet = ap;
this.text = s;
this.wadd = s1;
addMouseListener(this);
setForeground(fcolor);
public void paint(Graphics g){
super.paint(g);
if (getForeground() == lcolor){
Dimension d = getSize();
g.fillRect(1,d.height-5,d.width,1);
public void update(Graphics g){paint(g);}
public void mouseClicked(MouseEvent e){
try{
URL url = new URL(wadd);
applet.getAppletContext().showDocument(url,"_self");
catch(MalformedURLException er){ }
public void mouseEntered(MouseEvent e){
setForeground(lcolor);
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
repaint();
public void mouseExited(MouseEvent e){
setForeground(fcolor);
setCursor(Cursor.getDefaultCursor());
repaint();
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public static void main (String[] args){
new linkIt();
} -
I am new to Flex 2. I have downloaded and in the process of
reading the Adobe Documentation on using Flex 2 (Getting Started
with Flex 2, and Using Flex 2). Could someone direct me to an area
of documentation on the technique for adding a hyperlink to a
control? For example, how do you add a navigate to URL to a button?
Thanks.
TomFlex has a LinkButton which presents itself as bold-faced
text (you can change that with styles). When you mouse-over it
highlights; clicking the mouse generates a click event:
<mx:LinkButton label="Adobe" click="navigateToURL(new
URLRequest('
http://www.adobe.com'))" />
If you look closely you'll see that there are single quotes
around the url address.
Maybe you are looking for
-
I can't open iTunes.I've tried everything. help!
When I try to open iTunes i get this msg : The file iTunes Library.itl cannot be read because it was created by a newer version of iTunes. I don't want to be doomed to never using my ipod. pls help
-
Each time i close firfox my 'new tab' button disapears off my toolbar
I usuall customise my toolbar by dragging the new tab box there. However recently each time i have closed firefox its disappeared? I have to add it again every time. Does anyone know how can I stop this happening? Thanks in advance :D
-
The basic issue: Dreamweaver/Flash hangs indefinitely at the welcome screen after being opened and cannot be used/ must be forced quit. I can’t click anything and certainly can use the program. My System: Intel Mac Pro Two 2.66 Ghz Intel Processors 2
-
Hi, My situation: I have a applicationserver with Oracle BI Enterprise and a databaseserver with a Oracle 10G database. I make the connection with the database through ODBC. For this connection, networksupport has opened port 1521 in the firewall to
-
I am trying to migrate Essbase users to Shared Services and I get the following error: Error: 1051449: Essbase failed to get group with Error [CSS Error: Invalid Argument: Principal passed is NULL] Any ideas? Thank you!