|
| ||||||||||
| Tags: html, setfont, setforeground, swing components |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| How to use HTML in Swing Components?
I really want some help from you guys again. Last time your help was tremendous. So thought that posting to you would be helpful. I want to specify that a component's text has HTML format. I have tried lot of things but was not getting the desired output. So, please tell me how to use HTML in Swing Components.?? Please help me as soon as possible.!! ![]()
__________________ ~*~Silent~Kid~*~ "To The World You May Be Just One Person, But To One Person You May Be The World" |
|
#2
| ||||
| ||||
| Re: How to use HTML in Swing Components?
You should be knowing some basics of the swing components. Many swing components display a text string as part of their GUI. A component's text is displayed in one font and color by default. And this comes on one line. The font and color of text that is contained in a container can be determined by invoking some component's methods. These methods are setFont and setForeground methods. you can use HTML, when you want to mix fonts or colors within the text.
__________________ Signatures reduce available bandwidth |
|
#3
| ||||
| ||||
| Re: How to use HTML in Swing Components?
By using the setFont and setForeground methods, you can change the font and color of a component's text. You will have to invoke only that methods. The following code can help you for creating a label. Also you can set it's font and color by using the same code : Code: label = new JLabel("Label Example");
label.setFont(new Font("Comic Sans MS", Font.PLAIN, 16));
label.setForeground(new Color(0x00ffdd));
__________________ The FIFA Manager 2009 PC Game |
|
#4
| ||||
| ||||
| Re: How to use HTML in Swing Components?
You can specify a component's text which is having the HTML format. You will have to put the <html> tag at the beginning of the text, when you want to specify that a component's text has HTML formatting. Once you use this, you can use any valid HTML in the remainder. If you want to use HTML in a button, you can use the following code : HTML Code: button = new JButton("<html><b><u>Trial</u>Example</b><br>lhere</html>"); |
|
#5
| |||
| |||
| Re: How to use HTML in Swing Components?
I have provided you the code so that you can understand more clearly. The following code specifies the text formatting for the two buttons : HTML Code: b1 = new JButton("<html><center><b><u>D</u>Example</b><br>"
+ "<font color=#0000dd>First Button</font>",
leftButtonIcon);
Font font = b1.getFont().deriveFont(Font.PLAIN);
b1.setFont(font);
...
b2 = new JButton("Second Button", rightButtonIcon);
b2.setFont(font);
b2.setForeground(new Color(0x0000dd));
... |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How to use HTML in Swing Components?" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Layout manager for Swing Components in JAVA | afidelino | Software Development | 3 | 30-01-2011 03:28 AM |
| Jms + swing | Prince$O$Persia | Software Development | 5 | 24-07-2010 03:30 AM |
| Java SWING Components - Table Models | Isiah | Software Development | 5 | 21-07-2010 01:34 AM |
| What are JFC and Swing? | DANIEL 602 | Software Development | 5 | 14-02-2010 03:11 AM |
| what is the difference between Swing and Awt? | Deepest BLUE | Software Development | 4 | 27-11-2009 05:52 PM |