Пример #1
0
  private void initComponents() {
    filterField = new JComboBox();
    createSortField();
    createFilterText();
    ascending = new JCheckBox("Ascending (uncheck = Descending)");
    JLabel filterLabel = new JLabel("Filter:");
    JLabel sortLabel = new JLabel("Sort:");

    filterField.setModel(new DefaultComboBoxModel(Task.getFields()));
    sortField.setModel(new DefaultComboBoxModel(Task.getFields()));
    ascending.setSelected(true);

    GroupLayout layout = new GroupLayout(this);
    this.setLayout(layout);

    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(true);

    layout.setHorizontalGroup(
        layout
            .createSequentialGroup()
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.TRAILING)
                    .addComponent(filterLabel)
                    .addComponent(sortLabel))
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(filterField)
                    .addComponent(sortField))
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(filterText)
                    .addComponent(ascending)));
    layout.setVerticalGroup(
        layout
            .createSequentialGroup()
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(filterLabel)
                    .addComponent(filterField)
                    .addComponent(filterText))
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(sortLabel)
                    .addComponent(sortField)
                    .addComponent(ascending)));
  }
Пример #2
0
  private void createSortField() {
    sortField = new JComboBox(Task.getFields());
    sortField.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            commandDispatcher.dispatch(
                CommandDispatcher.Command.SORT_LIST, (String) sortField.getSelectedItem());
          }
        });
  }