|
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(); } }
|
- [JAVA2D] Question on multiple lines of JButton tex... Doal Miller
- Re: [JAVA2D] Question on multiple lines of JB... Jim Graham
- Marijn H. van der Ploeg
