JTabbedPane-选择新标签后,如何设置属性?

时间:2018-11-13 19:12:00

标签: java swing jtabbedpane

如果有人可以指出我对Java和Swing的了解,我将是不熟悉的。

这是一门建立我的框架的班级。我相信我必须使用您看到添加的ChangeListener,但是除了从该站点复制方法外,什么也没有做。 我想用选项卡完成的所有操作都是:如果单击另一个选项卡,则将它们设置为默认状态。.只是意味着将文本字段和列表选择设置为状态等。

我是否需要在面板或框架的类中使用此方法?我需要更改任何范围吗?我一直在寻找答案,但没有找到我想要的东西。

public class GUIFrame extends JFrame implements ChangeListener {

JTabbedPane tabs;

public GUIFrame(String title) {
    JFrame frame = new JFrame(title);
    Container c = frame.getContentPane();
    pack();
    buildGUI(c);
    setFrameAttributes(frame);
}
private void buildGUI(Container c) {
    tabs = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT);
    MedicalSystemIO medLogs = new MedicalSystemIO();
    c.setLayout(new BorderLayout());
    c.add("Center", tabs);
    tabs.addTab("Specialty", new SpecialtyPanel(medLogs.getListOfSpecialties()));
    tabs.addTab("Doctor", new DoctorPanel(medLogs.getListOfDoctors()));
    tabs.addTab("Patient", new PatientPanel(medLogs.getListOfPatients()));
    tabs.addTab("Treatment", new TreatmentPanel(medLogs.getListOfTreatments(), medLogs.getListOfPatients()));
    tabs.addChangeListener(this);

}

@Override
public void stateChanged(ChangeEvent e) {
    // TODO Auto-generated method stub
    if(e.getSource() instanceof JTabbedPane)
        tabs = (JTabbedPane) e.getSource();
        System.out.println("Selected paneNo : " + tabs.getSelectedIndex());
}

这是来自“ public TreatmentPanel(...)”类的方法。我没有包括大多数方法,但使用的一些方法是ActionListener和ListSelectionListener。

    private void buildPanel(ArrayList<Treatment> treatments, ArrayList<Patient> patients) {

    setLayout(new BorderLayout());

    model = new DefaultListModel<Treatment>();
    list = new JList<Treatment>(model);
    list.setModel(model);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSize(20,80);
    list.setFixedCellWidth(150);
    scroll = new JScrollPane(list, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    this.patients = new ArrayList<Patient>(patients);
    this.treatments = new ArrayList<Treatment>();

    JPanel jpaInput = createInputPanel();
    JPanel jpaProcess = createProcessPanel();
    JPanel jpaOutput = createOutputPanel();

    add("North", jpaInput);
    add("South", jpaProcess);
    add("Center", jpaOutput);
}

0 个答案:

没有答案