HI,
I am using BoxLayout. That seems to be fine as long as the components are not panel.
Here is what i am trying out. I have a panel (i have written it as a class called CustomPanel)
public class CustomPanel extends JPanel
{
private JLabel customLabel;
private JTextField customField;
private BoxLayout boxLayout;
public CustomPanel(String pLabelText,int pNumberOfChars)
{
customLabel = new JLabel(pLabelText);
customField = new JTextField(pNumberOfChars);
customField.setMaximumSize (customField.getPreferredSize());
boxLayout = new BoxLayout(this,BoxLayout.X_AXIS);
setLayout(boxLayout);
add(customLabel);
add(customField);
}
public void setPanelTitle(String pPanelTitle)
{
setBorder(BorderFactory.createTitledBorder(pPanelTitle));
}
}
now i use objects of this class on another panel which also is set to BoxLayout, as follows
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.util.*;
public class CustomTradingPanel extends JPanel
{
private CustomPanel customPanel;
public CustomTradingPanel()
{
setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
}
public void addComponents(String pLabelText,int pNumberOfChars)
{
CustomPanel localCustomPanel = new CustomPanel(pLabelText,pNumberOfChars);
customPanel = localCustomPanel;
customPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
add(customPanel);
add(Box.createRigidArea(new Dimension(0,5)));
}
public void setComponents(String pPanelTitle)
{
setBorder(BorderFactory.createTitledBorder(pPanelTitle));
}
}
now the problem i face is as follows :
I want to align the all the CustomPanel objects on the CustomTradingPanel such that all the customField objects are left aligned (on the same axis). How do i do that? or is there any other layout that would help me achieve this.
I do not want to use grid layout since the sizes of each component changes.
thanks in advance.
regards
Sudha