Beginner Questions adusting button hight ...

Swing Designer allows you to quickly create the frames, panels, dialogs, applets and other UI elements that comprise Java Swing applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Beginner Questions adusting button hight ...

Postby Karl » Fri Jun 05, 2009 5:42 am

Dear Folks,

I do want a Swing JButton array,
organized using a Swing BoxLayout,
have the same hight. In ohter words
all JButtons should have the same
hight as their JPanel container.

First there is a panel (BoxLaout)
then there is a rigit, 9 JButtons, and a final rigit.
The JPanel has a prefered hight of 55,
and I want that the JButtons to also have
the hight of 55 pixels. I changed min and prefered size
but those changes have no effect?

Thanks in advance,
Karl
Karl
 
Posts: 9
Joined: Tue Jun 02, 2009 12:51 am

Re: Beginner Questions adusting button hight ...

Postby Eric Clayberg » Fri Jun 05, 2009 7:54 am

Please post your complete example.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Beginner Questions adusting button hight ...

Postby Karl » Mon Jun 08, 2009 2:09 am

O.K. here comes a small example,
if you switch between Y-Axis and X-Axis
you see a difference. With Y-Axis all the buttons
have the same size (same width),
with X-Axis all the buttons do not have the same
height. The same behavior I do see when I compose
the GUI using the Swing Designer. I am looking for
a way to use the X-Axis BoxLayout for a sequence of
JToggleButtons where the buttons are allowed to have
different widths while having the exactly same height:

Code: Select all
import java.awt.Component;
import java.awt.Container;

import javax.swing.JFrame;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.BoxLayout;

public class SameHight {

   public static void main( String args[] ) {

      JFrame frame = new JFrame("Box Example");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      Container contentPane = frame.getContentPane();

      JPanel panel = new JPanel();
      // panel.setLayout( new BoxLayout( panel, BoxLayout.Y_AXIS ));
      panel.setLayout( new BoxLayout( panel, BoxLayout.X_AXIS ));
      contentPane.add(panel);

      JButton b1 = new JButton("<html><body>Button 1</html></body>");
      panel.add(b1);
      JButton b2 = new JButton("<html><body>Button 2<br>Spring Water</html></body>");
      panel.add(b2);
      JButton b3 = new JButton("<html><body>Button 3</html></body>");
      panel.add(b3);
      JButton b4 = new JButton("<html><body>Button 4<br>Fountain Water</html></body>");
      panel.add(b4);
      JButton b5 = new JButton("<html><body>Button 5</html></body>");
      panel.add(b5);
      JButton b6 = new JButton("<html><body>Button 6<br>Moutain Spring Water</html></body>");
      panel.add(b6);

      frame.pack();
      frame.setVisible(true);
   }
}
Karl
 
Posts: 9
Joined: Tue Jun 02, 2009 12:51 am

Re: Beginner Questions adusting button hight ...

Postby Eric Clayberg » Mon Jun 08, 2009 5:44 am

Try setting the maximum size of each button to match the tallest button. For example,

Code: Select all
b1.setMaximumSize(new Dimension(0, 37));
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to Swing Designer

Who is online

Users browsing this forum: No registered users and 1 guest