Here is a possible fix if you're using swing:

/**
You can use ANY JComponent that you like. Basically, any JComponent inherits
the setLayout
function and you can use this to your advantage This relieves the problem of
making
static gifs and icons and such. This way, you can change the text easily and
manipulation
of how you want the text to sit in the JComponent is all handled through the
layout manager
of your choice. I hope this helps.
*/
import com.sun.java.swing.*;
import java.awt.*;
import java.util.*;

class multiLineButton extends JFrame
{
 multiLineButton()
 {
  file://create button1
  JButton button1 = new JButton();
  file://set gridlayout manager to button1
  button1.setLayout(new GridLayout(2,1,0,0));//row,col.hgap,vgap
  file://add 2 labels to the button (2 rows as specified above)
  button1.add(new JLabel("first line"));
  button1.add(new JLabel("second line"));

  file://add multiLineButton to the frame
  this.getContentPane().setLayout(new FlowLayout());
  this.getContentPane().add(button1);

  file://size to fit in the frame
  this.pack();
 }
}

 file://test stub
 public static void main(String[] args)
 {
  file://instantiate a new frame
  multiLineButton frame = new multiLineButton();
  file://show the frame
  frame.show();
 }
}
----- Original Message -----
Sent: Wednesday, May 24, 2000 10:08 PM
Subject: [JAVA2D] Question on multiple lines of JButton text

I am trying to put 2 lines of text on a JButton. I have tried JButton1.setText("abc\ndef") and JButton1.setText("abc\rdef"), but the \n and \r characters are just treated as unprintable. I already have an icon in the button and I want to have the text settable at run time so I can't use an icon for one line of text. I know you use HTML in button text but I guess the version of swing I am using doesn't support it because I just see the tags when I try putting them in.
 
Is there a way to put multiple lines of text in a JButton? I am trying to make a button that looks like this, with settable text. The F1 in the corner is an icon. I had trouble getting the icon close to the edge but I finally got it close enough by making it the full button width.
 
__________________
|                               |
|   F1                       
|
|                               |
|    Text settable at      |
|     runtime.              |
|                               |
|                               |
---------------------------

 

Doal Miller

Fulcra

email: [EMAIL PROTECTED]

voice: (858) 874-7162

fax: (858) 571-1208

 

Reply via email to