Link in a JLabel

Hi,
How can I make part of the JLabel text similar to an HTML link? Let's say I have a label with text..
"Do you want more information about this program? Click here"
Only the Click here part is a link and when clicked, opens a new JFrame.

you could add a mouseListener to the JLable and when they click on it you could open a new JFrame()

Similar Messages

  • JLabel href link clicking

    With the JEditorPane we can configure an HTMLEditor kit to handle clicking on the link.
    With JLabel I can provide the text
    <html><body>Well <a href="dosomething">click me</a>, hmm no <a href="somethingelse">click me</a></body></html>and it will display two links that looks clickable.
    Is it possible to determine that either link was clicked on in a JLabel?

    That makes sense of course. But I found out I am stuck because I have the JLabel as the renderer of a table and I cant get the mouse click to forward to the renderer. And then if I had 2 labels in one cell I need to be able to forward the click to the right label. hmm. I will post a different question...

  • JLabel Icon error

    Hello to everyone,
    I've recently tried to add a photo on JLabel within my project.. I opened a package for images, and I just linked then in JLabel properties -> Icon section.. But it gives an exception like "*Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException*
    *at javax.swing.ImageIcon.<init>(ImageIcon.java:167)*"
    . I googled it; some of webs say it is a bug.. I don't have any other things except a jlabel, and photos.. When I tried to add photo from a direct path; there's no problem; but I want to add it in project; because I'll make it a jar archive.. So they(images) have to be in project folder... Again, I didn't write any codes.. Just used GUI to add photo..
    Thanx for advance..
    With regards..

    If you don't want to help, you don't have to replyYes we do have to reply because this is not the proper place to ask the question. Learn how to use the forums properly.
    Anyway We can't help because you don't know how to ask a question.
    Your question is referring to some code that was generated by an IDE. We have no idea what IDE you are talking about.
    This is not a forum for answering IDE questions. So go to your IDE forum and ask a question.
    Or learn how to write the code yourself and then you can post a question on the Java Swing forum.
    Start by reading the Swing tutorial on "How to Use Icons".

  • How to implement hyperlink in java using swing components

    hi.....
    pls help me to find out solution
    how to implement hyperlink in java using swing components

    I've got the same problem here.
    I want to implement a HyperlinkListener to a JLabel. (Unlike suggested above, it is only supported by JEditorPane and not JLabel)
    The goal is, that if a user clicks on a Link in a JLabel, the standard browser opens and displays that page.
    Can somebody please help?
    My ultimate goal would be to also be able to add clickable HyperLinks in ToolTip texts, but i guess that'd be even more complicated.

  • How to implement transactions in Tomcat using MySQL

    Hi,
    I am trying to find a way to implement Transactions in Tomcat 4112 using a DBCP connection pool with MySQL (connector/j 3.0.16).
    I am developing a web app using the Struts framework and have tried using JOTM for the transaction implementation. However the JOTM PreparedStatement objects do not support the getGeneratedKeys() method (which i definitely need!!!).
    I have one database with multiple datasources, but the dataase may become much larger and require multiple instances in the future so i want a solution that will scale.
    Can i use the simple JDBC connection.commit() methods? Are these robust? Or is there a simple way to use the base JTA/JTS implementation myself??
    Or is there something like JOTM that implements the full JDBC 3.0 interfaces!!
    lots of questions - sorry...
    thanks
    will crick

    I've got the same problem here.
    I want to implement a HyperlinkListener to a JLabel. (Unlike suggested above, it is only supported by JEditorPane and not JLabel)
    The goal is, that if a user clicks on a Link in a JLabel, the standard browser opens and displays that page.
    Can somebody please help?
    My ultimate goal would be to also be able to add clickable HyperLinks in ToolTip texts, but i guess that'd be even more complicated.

  • Adding a html link to JLabel

    Hi...
    So, what I want is a JLabel or maybe a JOptionPane to have a HTML link on it to a website and if the user clicks on said link I would like their default browser to fire up and hit that page. Thus in the below code I have a JLabel with "Java" showing and underlined like it is a link...now, how do I get this event processed?
    JLabel linkLabel =
    new JLabel("<html><a href="+"http://www.java.sun.com"+">Java</html>");
    TIA
    tfm

    search is your friend:
    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=%2Bforum%3A31&qt=hyperlink+label

  • Html link inside JLabel

    I write this code:
    String text ="<html><font size=2>Java-Editor</font>"
    +  "<P>"
    + "Homepage: <a href=\"www.b2m.it/ma\"> http://www.b2m.it</a></html>";
    JLabel textLabel = new JLabel(text);I show the jlabel inside a jdialog.
    When i press on hyperlink, the link don't work
    where is the error?

    You could use a java.awt.event.MouseListener on the label, it would be something like
    public class MyClass extends javax.swing.JFrame implements ajva.awt.event.MouseListener
         // public variables
         public MyClass()
              JLabel label = new JLabel("label text");
              label.addMouseListener(this);
              //other initializations          
         public void mouseClicked(java.awt.event.MouseEvent e)
              //handle click
         //other methods

  • HyperLink in JLabel

    How Can I create a HyperLink in JLabel ? is it possible ? plzz help ME..

    Do you want it to work, or just look like a hyperlink?
    I believe you can use html in a label by wrapping the text in <html></html> tags - e.g.
    JLabel myLabel = new JLabel("<html>my-link-html</html>");
    ...but to actually make it work is another story.
    I suspect you'd need at least an ActionListener to recognise the click and a HyperlinkListener to process the link, but that's way beyond anything I've done.
    Hope that helps a bit,
    Tim

  • How to define the position of a JLabel in a JPanel?

    Could anybody help me for my problem ?
    - I added two JLabel into a JPanle using the folowwing code, but the two labels are displayed over each other. JLabel.setBounds() doesn't help.
    questionL1 = new JLabel("question1");
    questionL1.setBounds(50, 200, 700, 50);
    questionL2 = new JLabel("question2");
    questionL2.setBounds(50, 250, 700, 50);
    graphicPanel = new JPanel();
    graphicPanel.setPreferredSize(new Dimension(850, 450));
    graphicPanel.setLayout(new BorderLayout());
    graphicPanel.setBackground(Color.white);
    graphicPanel.add(questionL1);
    graphicPanel.add(questionL2);
    Thanks in advance

    By default components get added to the 'center' of a BorderLayout, so questionL2 replaces questionL1 in the panel.
    Here is a link to the Swing tutorial on "Using Layout Managers":
    http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html

  • How to set a JButton,JTextfield, JLabel in a given location

    Hi am designing a login screen and i dont know how to set my JLabels and JButtons on the screen. Can some one pls help
    Thanx
    Edited by: nadeesha on Oct 2, 2007 2:21 AM

    nadeesha
    If you want to really learn, go to the javaTutorial.
    http://java.sun.com/docs/books/tutorial/uiswing/TOC.html
    If you don't want to learn but finish quick, here is :
    For login, you need JDialog, JLabel, JTextField, JButton,
    given location? --> You must know layout. --> if you want to learn go to the link above; learn The best is GridBagLayout.
    if you don't want to learn but finish quick, here is :
    // x, y, width, height  ==> you must put int value 
    class MyDialog extends JDialog {
      this.setLayout(null);
      JLabel myLabel = new JLabel("Login");
      myLabel.setBounds(x, y, width, height);
      myLabel.setBorder(new EtchedBorder()); ---> to see the actual bound of the component.
      JLabel myLabel2 = new JLabel("Password");
      myLabel2 .setBounds(x, y, width, height);
      myLabel2 .setBorder(new EtchedBorder()); ---> to see the actual bound of the component.
      JTextField myLoginTextField1 = new JTextField();  
      myLoginTextField1.setBounds(x, y, width, height);
      JTextField myPasswordTextField2 = new JTextField();
      myPasswordTextField2 .setBounds(x, y, width, height);
      JButton myOKButton = new JButton("OK");
      myOKButton.setBounds(x, y, width, height);
      JButton myCancelButton = new JButton("Cancel");
      myCancelButton.setBounds(x, y, width, height);
    {code}____________________________________________________
    This will do.  Etched border will help you to have proper size. of width and height.
    Play around, you will find fun -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • JPanel doesn't show new text after JLabel edit

    Hello,
    I am trying to create a custom progress bar-esk window to show users during lengthy methods.
    I have a new Thread which creates and displays a new ProgressWindow object (a JFrame with a JPanel and JLabel attatched). At second intervals the text of the JLabel attatched to this frame will change. however the text seen in the window is not updated.
    System.out's show the value of the JLable to be correctly changing.
    Here is the code for creating the Thread and window:
         Runnable r = new Runnable() {
                        public void run() {
                            try {
                                prog = new ProgressWindow();//creates the frame
                                prog.addStuff();//adds the components
                                prog.addListeners(inter);
                               while(true){
                                   prog.makeAnimation();
                            } catch (InterruptedException ex) {
                                ex.printStackTrace();
                            } catch (IOException ex) {
                                ex.printStackTrace();
                   new Thread(r).start();and the code within the ProgressWindow class which updates the label
    public void makeAnimation() throws InterruptedException, MalformedURLException {
            Thread.sleep(1000);
            if (dots == 0) {
                System.out.println("dots 0");
                labelPanel.remove(dotty);
                dotty = new JLabel("Analysing input  ");
                labelPanel.add(dotty);
                labelPanel.repaint();
                dots++;
            } else if (dots == 1) {
                System.out.println("dots 1");
                labelPanel.remove(dotty);
                dotty = new JLabel("Analysing input .");
                labelPanel.add(dotty);
                labelPanel.repaint();
                dots++;
            } else if (dots == 2) {
                System.out.println("dots 2");
                labelPanel.remove(dotty);
                dotty = new JLabel("Analysing input ..");
                labelPanel.add(dotty);
                labelPanel.repaint();
                dots++;    
            } else if (dots == 3) {
                System.out.println("dots 3");
                labelPanel.remove(dotty);
                dotty = new JLabel("Analysing input ...");
                labelPanel.add(dotty);
                labelPanel.repaint();
                dots = 0; 
        }I assume this is a threading issue, however I don't understand why the value is correctly changing, but not being repainted. I'd appriciate any insight :)
    thanks :)

    Fillis52 wrote:
    ..As for the SSCCE, I have looked at the linked site and honestly thought I had met the requirements. The code was formatted, and only the methods which presented the problem were given. Should I have included the code to create the window also?The first 'S' seems covered, but it is not SC, C or an E. Which part of the words associated with those letters are you having trouble understanding?
    If you had copy/pasted your code into the STBC (as recommended in the SSCCE document), it would have been obvious that it was not an SSCCE.
    Instead of being rebuked, I should be told what is missing from my post in order to create a SSCCE as i obviously dont know how to do it properly.You expect us to have a crystal ball? Instead of complaining, it would be more productive to be specific about what part of S-SC-C-E document you do not understand. And this time, read it carefully, don't skim it.

  • JLabel with HTML visible only for the first time

    I've implemented a really simple applet:
    public class TestApplet extends JApplet {
      @Override
      public void init() {
        try {
          SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
              JPanel topPanel = new JPanel();
              topPanel.setLayout(new BorderLayout());
              getContentPane().add(topPanel);
              JLabel labelHello = new JLabel("<html>Hello World!</html>");
              topPanel.add(labelHello, BorderLayout.NORTH);
              JLabel labelHelloNoHTML = new JLabel("Hello World - without html!");
              topPanel.add(labelHelloNoHTML, BorderLayout.SOUTH);
        } catch (Exception e) {
          System.err.println("Couldn't initialize GUI");
    }And there are two html pages, both having the same applet and a link referring to each other:
    index.html
    <html>
           <head><title>Applet</title></head>
           <body>
                  <div><a href="link.html">Link</a></div>
                  <div>
                        <applet hspace="0" height="375" align="left" width="600" vspace="0" mayscript="" alt="GetJava" codebase="./"
                        code="com.test.TestApplet" name="TestApplet"></applet>         
                  </div>
           </body>
    </html>link.html
    <html>
           <head><title>Applet</title></head>
           <body>
                  <div><a href="index.html">Link</a></div>
                  <div>
                        <applet hspace="0" height="375" align="left" width="600" vspace="0" mayscript="" alt="GetJava" codebase="./"
                        code="com.test.TestApplet" name="TestApplet"></applet>         
                  </div>
           </body>
    </html>Now when I navigate to index.html the applet shows correctly both labels but in case I jump to link.html the applet shows only the second label i.e. Hello World - without html! . This seems to be specific to Java version 1.6.0_21 and 1.6.0_22, it was working properly in 1.6.0_17. Is anyone else experiencing similar issue or am I missing something?
    Edited by: user13135196 on Nov 25, 2010 4:33 AM
    Edited by: Slavek Tecl on 25.11.2010 13:12

    I am having this exact same issue. I have a JLabel with <html> for superscript in my JApplet. The first time I run my applet it displays fine. All subsequent times (refresh the page, or close the tab then open again) the JLabel with <html> doesn't show. This issue does NOT occur in the Eclipse Applet Viewer, but does occur with Google Chrome9 and IE8.
    I spent forever checking my methods and changing things trying to figure out why all the other labels show. Never would have guessed <html> in a JLabel would make it not display. This is terrible bug. Please fix ASAP.

  • Link in a GUI

    Greetings,
    I wish to add a link to my JAVA application program GUI. i.e. i will add a label representing my email address, so when a person clicks it, it automatically opens the computers email program eg. Outlook express with the email address placed in the To box.
    Like a hyper link. How can I make a link to a website that way too?
    Thank you,
    RamboTango

    Round your text string of JLabel <HTML>...</HTML>.
    For example:
    label = new JLabel("<HTML><B>Your Text</B>on label:</HTML>");
    You my use close tags </B> or </HTML> or not use - as you wish.

  • How can i add url link in an application.

    Hi,i want to add link in an application mean i want to add url link in JFrame.thanks

    add a JLabel to the frame like
    String link = "<html><body><a hreff=put your link here>click here</a></body></html>"
    JLabel myLable = new JLabel( link );enjoy ;-)

  • JLabel spacing

    I have a component with a JLabel above it. Both of these components are centered relative to the component that is next to it. However, it is not coming out quite right. It appears that the JLabel has 4 pixels of extra space above it. This spacing I believe is due to the font and not from the insets of the GridBagLayout. If I double the size of the JLabel's font, the spacing increases to 8 pixels. I also tested this with a small program that adds a single JLabel to a JFrame:
    public class MainClass {
      public static void main(String[] args) {
        javax.swing.JFrame frame = new javax.swing.JFrame();
        javax.swing.JLabel label = new javax.swing.JLabel("Environment-gy");
        label.setBackground(java.awt.Color.RED);
        frame.getContentPane().add(label);
        frame.getContentPane().setBackground(java.awt.Color.RED);
        frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }If you run this, you will notis that the "gy" in the label has only a single pixel of spacing below, but there are 4 pixels of spacing above the text. Is there any way to remove these 4 pixels? The components do not center correctly with them in there. Even in the test program, the label does not appear to be centered exactly. It appears to be too far down from the top, albeit subtely.
    I cannot just kludge this, however, because this application will be run on a number of different environments and there is no way to know what exact font and font size will be used.

    In the future Swing related questions should be posted in the Swing forum.
    If the past you have been given a link to the Swing tutorial, specifically you have been given the link on "How to Use Layout Managers". So read the tutorial, choose the appropriate layout manager and use the appropriate methods to control the spacing.

Maybe you are looking for