I am trying to create a class which could be a subpanel. It extends JPanel and implements AdjustmentListener. The JPanel is used here as a container and it keeps JLabels and JScrorrButtons layouted with gridBagLayout.
This class instantiated in application doesn't work, none of components (labels and scroolButtons) don't even show up.
public class parameteManager extends JPanel implements AdjustmentListener{
public JPanel pane;
public JScrollBar scrbF;
public JScrollBar scrbA ;
public JScrollBar scrbC ;
public JTextField wartF ;
public JTextField wartA ;
public JTextField wartC ;
public parameteManager(int a,int b,int c,int d,int e,int f,int g,int h,int i, int j,int k,int l,java.lang.String z) {
scrbF = new JScrollBar(JScrollBar.HORIZONTAL, a, b, c, d);
scrbA = new JScrollBar(JScrollBar.HORIZONTAL, e, f, g, h);
scrbC = new JScrollBar(JScrollBar.HORIZONTAL, i, j, k, l);
wartF = new JTextField ();
wartA = new JTextField ();
wartC = new JTextField ();
pane=new JPanel();
pane.setSize(500,300);
GridBagLayout gridbg = new GridBagLayout();
GridBagConstraints constr = new GridBagConstraints();
constr.insets=new Insets(2,2,2,2);
pane.setLayout(gridbg);
//adding components to the panel , to set all constraints needed for gridBagLayout buildConstraints function is used.
buildConstraints(constr, 0, 0, 1, 1, 30, 2,3,0);
constr.fill = GridBagConstraints.NONE;
constr.anchor = GridBagConstraints.EAST;
JLabel label1 = new JLabel("Faza:", JLabel.LEFT);
gridbg.setConstraints(label1, constr);
pane.add(label1);
//amplituda
//pokaz wart czestotl
wartC.setEditable(false);
wartC.setText(""+scrbC.getValue());
buildConstraints (constr,1,2,1,1,0,0,3,0);
constr.fill= GridBagConstraints.HORIZONTAL;
constr.anchor = GridBagConstraints.CENTER;
gridbg.setConstraints(wartC, constr);
pane.add(wartC);
pane.setBorder(BorderFactory.createTitledBorder("Manager O"+z));
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void adjustmentValueChanged(AdjustmentEvent e) {
Object source = e.getSource(); //scrbF scrbA scrbC - zrodlo zdarzenia
if (source == scrbF) {
int value=scrbF.getValue();
wartF.setText(""+value);
}
if (source == scrbA){
int value=scrbA.getValue();
wartA.setText(""+value/10);
}
if (source == scrbC){
int value=scrbC.getValue();
wartC.setText(""+value);
}
}
private void buildConstraints(GridBagConstraints gbc, int gx, int gy,
int gw, int gh, int wx, int wy,int px, int py) {
//gbc.insets = new Insets(5,5,3,5);
gbc.gridx = gx;
gbc.gridy = gy;
gbc.gridwidth = gw;
gbc.gridheight = gh;
gbc.weightx = wx;
gbc.weighty = wy;
gbc.ipadx=px;
gbc.ipady=py;
}
private void jbInit() throws Exception {
}
}
//the applicaion that uses parameteManger class
public class Chart extends JFrame implements AdjustmentListener{
parameteManager managerx,managery; //subpanels
JPanel contentPane;
public Chart(){
super ("Chart");
contentPane = new JPanel();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
//contentPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
managerx= new parameteManager(2,0,0,6,60,0,60,100,2,0,0,100,"X");
managery= new parameteManager(2,0,0,6,60,0,60,100,2,0,0,100,"Y");
contentPane.add(managerx);
contentPane.add(managery);
setContentPane(contentPane);
setTitle("Chart");
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args){
JFrame frame = new Lissajous1();
ExitWindow exit = new ExitWindow();
frame.addWindowListener(exit);
frame.show();
}
public void adjustmentValueChanged(AdjustmentEvent e) {
Object source = e.getSource(); //scrbF scrbA scrbC - zrodlo zdarzenia
if (source == managerx.scrbF) {
int value=managerx.scrbF.getValue();
}
if (source == managerx.scrbA){
int value=managerx.scrbA.getValue();
}
if (source == managerx.scrbC){
int value=managerx.scrbC.getValue();
}
}
private void jbInit() throws Exception {
this.setResizable(false);
}
}
what could be wrong with it... maybe it is the case of event handling?? any idaes?