Solved

Formatting button labels

Posted on 2002-04-29
11
230 Views
Last Modified: 2010-08-05
I need to change the font size, style and color of button labels.
Thnx in advance for your help.
0
Comment
Question by:rvaldivia
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 6978075
If you're using Swing, you can do:

String labelText =
      "<html><FONT COLOR=RED>Red</FONT> and " +
      "<FONT COLOR=BLUE>Blue</FONT> Text</html>";
    JLabel coloredLabel =
      new JLabel(labelText, JLabel.CENTER);


   
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 6978085
Or, more like your requirement:
JButton myButton = new JButton("<html><font color=\"red\">Hello World</font></html>");
0
 

Author Comment

by:rvaldivia
ID: 6978088
I doing applets,I'm not using html.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 6978112
Doesn't matter
0
 

Author Comment

by:rvaldivia
ID: 6978118
I doing applets,I'm not using html.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:rvaldivia
ID: 6978145
When I want to create a button I do the following

Button MyButton= new Button("Hello");

I am not using JButton.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 6978178
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().setBackground(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) { }

}
0
 
LVL 92

Expert Comment

by:objects
ID: 6978883
To do what you want with AWT you'll need to handle the painting of the button yourself.
0
 
LVL 9

Accepted Solution

by:
Ovi earned 200 total points
ID: 6979593
About font  and font size, use button.setFont(new Font("Arial", Font.PLAIN, 11));
For color button.setForeground(Color.blue)/button.setBackground(Color.white)

About style, kwhat you are refering on ? As bold and italic you could use with the font object like button.setFont(new Font("Arial", Font.BOLD, 11)); if you are thinking on more complex behaviuor/look, objects has right, you must overwrite the paint method of your button and handle your customization there. You can do that by subclassing a normal button.
0
 

Author Comment

by:rvaldivia
ID: 7840641
Thanx, just what I needed.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 7843710
me too :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 86
JAVA part two 5 58
Java. Convert method from recursion based to iteration based ( loop based ) 6 77
how do i compare an object based on two fields 6 49
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now