Changing Panel view from
To: comp.lang.java.gui
Hi all.
I hava a problem with my Gui. I have:
1 Frame with 2 panels (JPanel)
on first JPanel I have JComboBox object
and on second panel i want to have different objects for each
JComboBox Item :(JSlider, JTable etc) and i dont know how to do this.
I'm beginner in java
My code that works bad (creating a another Jpanel inside second JPanel
depending of choice JComboBox)
public class MainFrame extends JFrame{
(...kod...)
public MainFrame(){
(...kod...)
//mainDesktops@MainFrame
//1->z modelami
mainDesktop1 = new JPanel();
comboBox =new JComboBox();
mainDesktop1.add(comboBox);
comboBox.setBackground(Color.WHITE);
for(int i=0; i<comboBoxItems.length;i++)
comboBox.addItem(comboBoxItems[i]);
comboBox.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent eve){
mainDesktop2.removeAll();
mainDesktop2.validate();
mainDesktop2.add( setView(comboBox.getSelectedIndex()),BorderLayout.CENTER );
validate();
}//actionPerf
});
//2 -> opcje modeli
mainDesktop2 = new JPanel();
titleBorder2 =
BorderFactory.createLineBorder(Color.RED);
add(mainDesktop2,BorderLayout.CENTER);
mainDesktop2.setBackground(Color.BLACK);
mainDesktop2.setBorder(new
javax.swing.border.TitledBorder(titleBorder2,titleBorder));
}//konstruktor
JPanel setView(int wybor){
JPanel pan = new JPanel();
if (wybor==0){
bscLabel.setText("\n BER - probablity: \n" +
(int)(bscKanal.getProbablity()*100) +"%");
bscLabel.setForeground(Color.BLUE);
bscSlider.setMajorTickSpacing(20);
bscSlider.setPaintTicks(true);
bscSlider.setPaintLabels(true);
bscSlider.setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
bscKanal.setProbablity(bscSlider.getValue()/
100);
pan.add(bscLabel);
pan.add(bscSlider,BorderLayout.AFTER_LAST_LINE);
}
return pan;
}
}//class
I will be thankfull if someone show a code that changing panel view
from JComboBox or any Idea how to do this
thanks
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24