Solved

Formatting button labels

Posted on 2002-04-29
11
229 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This video teaches viewers about errors in exception handling.
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 …

743 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

11 Experts available now in Live!

Get 1:1 Help Now