Orientation of panels in BoxLayout

Hi there!

I'm just having a problem. Maybe I didn't understand the explanation at http://java.sun.com/docs/books/tutorial/uiswing/layout/box.html...

So, my problem is, that I have a JPanel that contains a JTextPane and to JPanels. And I just wan't, that all components are aligned to the left side!

But it doesn't work :(

No matter if I use setAlignmentX/Y java makes quite funny things.

Here's my code, I hope that anybody could help me....

/**

*

* @param parentFrame

*/

public ImportWizard(JFrame parentFrame){

dialog =new JDialog(parentFrame);

dialog.setSize(450, 400);

dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

dialog.setTitle(LR.getString("Frame.Title"));

Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();

int x = ((int) screenDim.getWidth() - dialog.getWidth()) / 2;

int y = ((int) screenDim.getHeight() - dialog.getHeight()) / 2;

dialog.setLocation(x, y);

dialog.setResizable(false);

dialog.setModal(true);

}

/**

*

*

*/

publicvoid showDialog(){

mainPanel =new JPanel();

mainPanel.setLayout(new BoxLayout(mainPanel,BoxLayout.Y_AXIS));

mainPanel.setBorder(BorderFactory.createEmptyBorder(6,6,6,6));

mainPanel.add(getTopPanel());

mainPanel.add(getButtonPanel());

dialog.add(mainPanel);

dialog.pack();

dialog.validate();

dialog.setVisible(true);

}

/**

*

* @return

*/

private JPanel getTopPanel(){

if (topPanel ==null){

topPanel =new JPanel();

topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));

topPanel.add(getLeftImage());

topPanel.add(getWizardPanel());

}

return topPanel;

}

/**

*

* @return

*/

protected JPanel getWizardPanel(){

if (wizardPanel ==null){

wizardPanel =new JPanel();

wizardPanel.setLayout(new BoxLayout(wizardPanel,BoxLayout.PAGE_AXIS));

wizardPanel.setBorder(BorderFactory.createEmptyBorder(6,6,6,6));

wizardPanel.setPreferredSize(new Dimension(400,200));

wizardPanel.add(getHeaderText());

wizardPanel.add(getCertificatePanel());

wizardPanel.add(getCrlPanel());

}

return wizardPanel;

}

/**

*

* @return

*/

private JTextPane getHeaderText(){

if (headerText ==null){

headerText =new JTextPane();

headerText.setEditable(false);

HTMLEditorKit html =new HTMLEditorKit();

headerText.setEditorKit(html);

headerText.setBackground(java.awt.SystemColor.control);

headerText.setText(LR.getString("Wizard.HeaderText"));

}

return headerText;

}

/**

*

* @return

*/

private JPanel getCrlPanel(){

if (crlPanel ==null){

crlPanel =new JPanel();

crlPanel.add(getCrlPane());

crlPanel.add(getNewCrlButton());

}

return crlPanel;

}

/**

*

* @return

*/

private JPanel getCertificatePanel(){

if(certificatePanel ==null){

certificatePanel =new JPanel();

certificatePanel.add(getCertificatePane());

certificatePanel.add(getCertificateButton());

}

return certificatePanel;

}

/**

*

* @return

*/

private JTextPane getCrlPane(){

if (crlPane ==null){

crlPane=new JTextPane();

crlPane.setEditable(false);

crlPane.setBackground(java.awt.SystemColor.control);

crlPane.setText(LR.getString("Wizard.RevokedList.Text"));

}

return crlPane;

}

/**

*

* @return

*/

private JButton getCertificateButton(){

if (certificateButton ==null){

certificateButton =new JButton(

LR.getString("Wizard.Certificate.Button"));

certificateButton.addActionListener(new java.awt.event.ActionListener(){

publicvoid actionPerformed(java.awt.event.ActionEvent e){

wizElem =new CertificateWizard();

initWizard();

}

});

}

return certificateButton;

}

/**

*

* @return

*/

protected JLabel getLeftImage(){

if (leftImage ==null){

leftImage =new JLabel();URL imageUrl = AboutBox.class.getResource("rlagkey.gif");;

ImageIcon icon =new ImageIcon(imageUrl);

leftImage =new JLabel(icon);

}

return leftImage;

}

Thanks!!!

[8188 byte] By [niemayda] at [2007-10-2 20:43:25]
# 1
> Here's my code, I hope that anybody could help me....the fastest way to get help is to post a sample program that we can copy/paste/compile/runand see the problemdoesn't have to be your full program, just the shell with the components to align
Michael_Dunna at 2007-7-13 23:26:48 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks!Within my next question I'll post a runable part of my programm :)I solved that problem myself. You have to put all components in Panels, that's the only way I found to change their position and size.Regards Michael
niemayda at 2007-7-13 23:26:48 > top of Java-index,Desktop,Core GUI APIs...