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?