0

I'm using the seaglass look and feel in my application. How do I set the height for a JButton? It seems like there is no way to have a custom height. I took a look at the documentation: http://seaglass.googlecode.com/svn/doc/client-properties.html and I tought I had to use JComponent.sizeVariant = scale to solve the problem, but it doesn't work. How can I solve this?

Thanks trashgod, I tried this:

    try {
        UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
    } catch(Exception e) {
        e.printStackTrace();
    }
    JButton button = new JButton("Test");
    button.putClientProperty("JComponent.sizeVariant", "scale");

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(button);
    panel.setPreferredSize(new Dimension(500, 400));

    JFrame frame = new JFrame();
    frame.setContentPane(panel);
    frame.pack();
    frame.setVisible(true);

but doesn't seem to work either. Thanks anyway for your effort.

emanuele
  • 193
  • 1
  • 10

2 Answers2

3

As shown here, here and here, the JComponent.sizeVariant property value is a String, e.g. "mini", "small", "regular" and "large". For "scale" to work, the enclosing panel's layout must allow the component to resize. In the variation below, GridLayout is used:

f.add(variantPanel("scale"));
…
private static JPanel variantPanel(String size) {
    JPanel variantPanel = new JPanel(new GridLayout());
    …
    return variantPanel;
}

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • This isn't working the way I expected, but the example may be useful to you. – trashgod Dec 30 '13 at 11:28
  • @emanuele: Sorry; I'd say leave the question open for a time in hopes of a better answer; I'm wary of [`setPreferredSize`](http://stackoverflow.com/q/7229226/230513). – trashgod Dec 30 '13 at 13:43
  • it should have been panel.setPreferredSize, but I don't think it changes much. I edited the question anyway. – emanuele Dec 30 '13 at 14:35
  • @emanuele: It may help to focus on the broader goal. Can you elaborate? – trashgod Dec 30 '13 at 16:10
0

Your frame contains one panel. When you pack the frame the panel will be sized at 500x400, i.e., its preferred size. Your panel uses a BorderLayout. BorderLayout does not use the button preferred size. It will expand the button to fill the entire panel size. Try using a layout for your panel that respects the preferred size of its components, e.g., FlowLayout. If you want to change the button size you can then set the button's preferred size.