Solved

Formatting button labels

Posted on 2002-04-29
11
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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
 

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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

690 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