rvaldivia
asked on
Formatting button labels
I need to change the font size, style and color of button labels.
Thnx in advance for your help.
Thnx in advance for your help.
Or, more like your requirement:
JButton myButton = new JButton("<html><font color=\"red\">Hello World</font></html>");
JButton myButton = new JButton("<html><font color=\"red\">Hello World</font></html>");
ASKER
I doing applets,I'm not using html.
Doesn't matter
ASKER
I doing applets,I'm not using html.
ASKER
When I want to create a button I do the following
Button MyButton= new Button("Hello");
I am not using JButton.
Button MyButton= new Button("Hello");
I am not using JButton.
If you're not using Swing, you can't do this. If you are, the following will create a button with a red italic label:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
/**
*Description of the Class
*
* @author protean
* @created 29 April 2002
*/
public class TestApplet extends JApplet {
/**
*Description of the Method
*
* @since
*/
public void init() {
try {
getContentPane().setBackgr ound(Color .WHITE);
getContentPane().add(new JButton("<html><font color=\"red\"><em>Hello World</em></font></html>") );
this.setSize(new Dimension(400, 300));
}
catch (Exception e) {
e.printStackTrace();
}
}
//public void paint(Graphics g) { }
}
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
/**
*Description of the Class
*
* @author protean
* @created 29 April 2002
*/
public class TestApplet extends JApplet {
/**
*Description of the Method
*
* @since
*/
public void init() {
try {
getContentPane().setBackgr
getContentPane().add(new JButton("<html><font color=\"red\"><em>Hello World</em></font></html>")
this.setSize(new Dimension(400, 300));
}
catch (Exception e) {
e.printStackTrace();
}
}
//public void paint(Graphics g) { }
}
To do what you want with AWT you'll need to handle the painting of the button yourself.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanx, just what I needed.
me too :)
String labelText =
"<html><FONT COLOR=RED>Red</FONT> and " +
"<FONT COLOR=BLUE>Blue</FONT> Text</html>";
JLabel coloredLabel =
new JLabel(labelText, JLabel.CENTER);