Dear Nathan,
Actually I haven't used Text Button in my project, but I just have tried your case. And I also cannot set the size just using setSize() and getSize()
So I have tried another implementation and it seems to do
I have two solutions, and follow is my code:
One is rather simple, it just places all the button on the GridLayout but it is not so flexible.
And the other uses the getUI method, I don't know if it works for u, please tell me later...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.plaf.ButtonUI;
public class Test extends JFrame {
public Test(
String title) {
super(title);
/* another solution */
getContentPane().setLayout(new GridLayout(2, 1));
JButton lvB5 = new JButton("Long............................");
JButton lvB6 = new JButton("Short");
getContentPane().add(lvB5);
getContentPane().add(lvB6);
pack();
}
public static void main(String[] args) {
JFrame lvTest = new Test("Test frame");
lvTest.setBounds(100, 100, 200, 200);
lvTest.setVisible(true);
lvTest.setBackground(Color.black);
JDialog lvDialog = new JDialog(lvTest);
lvDialog.setBounds(200, 200, 200, 200);
lvDialog.getContentPane().setLayout(new FlowLayout());
JButton lvB3 = new JButton("Very longggggggggggg Button");
Dimension d = (lvB3.getUI()).getPreferredSize(lvB3);
System.out.println(d.getWidth());
System.out.println(d.getHeight());
JButton lvB4 = new JButton("Short");
lvB4.setPreferredSize(d);
lvDialog.getContentPane().add(lvB3);
lvDialog.getContentPane().add(lvB4);
lvDialog.pack();
lvDialog.setVisible(true);
}
}