Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Using a JLabel to use html elements

  1. #1
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Using a JLabel to use html elements

    I was able to create a, very poor, textarea with the html and textarea tags inside a JLabel. However, it's not letting me really alter the cols that much. Also, it won't do textfield.

    Also, how do I access the value of my textarea inside the JLabel? And how do I get the JLabel to do an href, i.e. become a link? I got the blue underline but it's not going anywhere.

       import javax.swing.JLabel;
       import javax.swing.JPanel;
       import javax.swing.JFrame;
       import java.awt.GridLayout;
       import javax.swing.JScrollPane;
     
       public class LabelFormExample extends JFrame
       {
     
     
          private JLabel form;
          private JPanel contentPane;
     
          public LabelFormExample()
          {
             super("Form");
             contentPane = new JPanel();
     
             setContentPane(new JScrollPane(contentPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
             setDefaultCloseOperation(EXIT_ON_CLOSE);
     
             form = new JLabel("<html><form><textarea rows=30 cols=30>    <br/> Wenguin <br/> <textfield> </textfield> <A HREF=http://www.w3schools.com/tags/att_textarea_cols.asp> Mongoose </A></form></html>");
             System.out.println(form.getText());
             contentPane.add(form);
             contentPane.setLayout(new GridLayout(5,1));
     
             contentPane.add(new JLabel("<html><A href=http://www.w3schools.com/tags/att_textarea_cols.asp> Website </A></html>"));
             setVisible(true);
     
             contentPane.add(new JLabel("<html><textfield text=mongoose></textfield></html>"));
     
             contentPane.add(new JLabel("<html><img src=C:/Users/Wenguin/Documents/Rikki2/Rikki2/Avíá1.jpg></img></html>"));
     
           contentPane.add(new javax.swing.JButton("<html><textarea rows=20 cols=20></textarea></html>"));
          }
     
     
          public static void main(String[] args)
          {
             new LabelFormExample();
     
          }
     
     
     
     
       }

    It made a textarea in the middle of a JButton!!!! That is totally bizarre!

    Seriously, how do you turn a JLabel into a hyperlink?

    I mean, is there an easier way than adding a MouseListener to it, then having a Desktop.getDesktop().browse() and having it underlined and setting the foreground to blue?

    Also, what other form elements and html elements can I access with JLabel and is it possible to get their values or add actions to them if they're buttons?
    Last edited by javapenguin; May 17th, 2012 at 09:43 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Using a JLabel to use html elements

    Moved to AWT / Java Swing ...please post in the appropriate category

Similar Threads

  1. Loop through JLabel and change JLabel
    By JoeBrown in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 11th, 2012, 12:52 PM
  2. Adding JLabel on other Jlabel
    By mike416 in forum AWT / Java Swing
    Replies: 3
    Last Post: March 29th, 2012, 11:50 AM
  3. JLabel
    By Poseidon in forum AWT / Java Swing
    Replies: 2
    Last Post: February 18th, 2012, 04:39 PM
  4. [SOLVED] ArrayList object's elements confusing??? doesnt replace the elements? set() method?
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: June 21st, 2011, 01:20 PM