Highlighting/Making Bold Button Text

Highlighting/Making Bold Button Text

How do I highlight or make bold the text in a button or a list?

Java Buttons, Lists, Labels, TextAreas, Canvases, etc, are all subclasses ofthe Java Component class which in turn defines generic methods for modifyingthe look and feel of Java’s UI elements. The following are some of themethods in java.awt.Component that allow you to query or change acomponent’s appearance on the screen:

        getFont()        setFont()        getForeground()        setForeground()        getBackground()        setBackground()        
For example, the applet below constructs a row of buttons, some with alteredfonts, some with altered colors (to produce the high-lighted effect), and alist item with non-default fonts and colors:
import java.awt.*;import*;import java.applet.*;//// Create a number of buttons with different fonts and colors.//public class ButtonTest extends Applet {        public void init() {                Button b1 = new Button(“Normal”);                add(b1);                Button b2 = new Button(“Bold”);                b2.setFont(new Font(“TimesRoman”, Font.BOLD, 14));                add(b2);                Button b3 = new Button(“Italic”);                b3.setFont(new Font(“TimesRoman”, Font.ITALIC, 14));                add(b3);                Button b4 = new Button(“Bold-italic”);                b4.setFont(new Font(“TimesRoman”, Font.ITALIC + Font.BOLD, 14));                add(b4);                Button b5 = new Button(“High-lighted”);                b5.setForeground(;                b5.setBackground(Color.yellow);                add(b5);                List l = new List(4, false);                l.setForeground(;                l.setBackground(;                l.setFont(new Font(“TimesRoman”, Font.ITALIC, 14));                l.addItem(“This is a test”);                l.addItem(“This is also a test”);                add(l);        }        //        // Defining a main() routine allows the applet to be        // run as a standalone java application        // using:  java ButtonTest        //        public static void main(String argv[]) {                Frame f = new Frame(“ButtonTest”);                Applet a = new ButtonTest();                a.init();                a.start();                f.setLayout(new BorderLayout());                f.add(“Center”, a);                f.pack();      ;        }}


Share the Post: