コード例 #1
0
  /*
   * The following method creates the textfield to change the text
   *     and the button to update the label.
   * postcondition: returns the panel containing the textfield and button.
   */
  public JPanel createUpdateButton() {
    JLabel textLabel = new JLabel(new String("Change text to: "));

    textField = new JTextField(new String("Big Java"), 20);
    textField.setFont(new Font(("Times"), Font.PLAIN, 12));

    update = new JButton(new String("Update"));
    update.setDefaultCapable(true);

    // This class is used to create a special ActionListener for this menu item
    class ButtonListener implements ActionListener {
      /*
       * This method is called when the update button is clicked
       */
      public void actionPerformed(ActionEvent event) {
        // Call the method to change the text on the screen.
        setSampleFont();
      } // end actionPerformed method
    }
    ActionListener listener = new ButtonListener();
    update.addActionListener(listener);

    JPanel panel = new JPanel();

    panel.add(textLabel);
    panel.add(textField);
    panel.add(update);

    return panel;
  } // end createUpdateButton method
コード例 #2
0
  private void initComponents() {
    // Message - JLabel
    lblMessage =
        new JLabel(
            String.format(
                "An unexpected error has occurred: %s",
                e == null ? "Unexpected exception" : e.getMessage()));
    lblMessage.setIcon(icon);
    lblMessage.setPreferredSize(new Dimension(360, 40));
    lblMessage.setBorder(BorderFactory.createLineBorder(Color.red));

    // txtTrace - ExceptionTracePane
    txtTrace = new ExceptionTracePane();
    txtTrace.setBackground(new Color(92, 0, 0));
    txtTrace.setException(e);

    // srlTrace - JScrollPane
    JPanel traceWrapper = new JPanel(new BorderLayout());
    traceWrapper.add(txtTrace, BorderLayout.CENTER);
    srlTrace = new JScrollPane(traceWrapper);
    srlTrace.setPreferredSize(new Dimension(360, 200));
    srlTrace.setVisible(false);

    // btnDetails - JButton
    btnDetails = new JButton(new DetailsButtonAction());
    btnDetails.setPreferredSize(new Dimension(100, 40));

    // btnClose - JButton
    btnClose = new JButton(new CloseButtonAction());
    btnClose.setDefaultCapable(true);
    btnClose.setPreferredSize(new Dimension(100, 40));
  }
コード例 #3
0
  public DialogButtonsPanel getButtonsPanel() {
    helpButton = new JButton("Help");
    helpButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            helpActionPerformed();
          }
        });

    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            cancelActionPerformed();
          }
        });

    finishButton = new JButton("Ok");
    finishButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            finishActionPerformed();
          }
        });

    finishButton.setDefaultCapable(true);

    return new DialogButtonsPanel(Arrays.asList(cancelButton, finishButton, helpButton));
  }
コード例 #4
0
 public JButton getReplaceButton() {
   if (replaceButton == null) {
     replaceButton = new JButton();
     replaceButton.setText("Replace");
     replaceButton.setMnemonic('R');
     replaceButton.setDefaultCapable(true);
     replaceButton.addActionListener(this);
   }
   return replaceButton;
 }
コード例 #5
0
 public JButton getFindNextButton() {
   if (findNextButton == null) {
     findNextButton = new JButton();
     findNextButton.setText("Find Next");
     findNextButton.setMnemonic('F');
     findNextButton.setDefaultCapable(true);
     findNextButton.addActionListener(this);
   }
   return findNextButton;
 }
コード例 #6
0
  private void createGUIDialog() {
    JPanel mainPanel = new JPanel(new BorderLayout());
    setContentPane(mainPanel);
    mainPanel.add(new JLabel("Select dimensions to rulerender: "), BorderLayout.PAGE_START);

    JPanel combosPanel = new JPanel(new GridLayout(2, 2, 10, 10));
    mainPanel.add(combosPanel, BorderLayout.CENTER);

    combosPanel.add(new JLabel("Dimension 1:"));
    box1 = new JComboBox(choices.toArray());
    box1.setEditable(false);
    box1.setSelectedIndex(0);
    combosPanel.add(box1);

    combosPanel.add(new JLabel("Dimension 2:"));
    box2 = new JComboBox(choices.toArray());
    box2.setEditable(false);
    box2.setSelectedIndex(Math.min(choices.size(), 1));
    combosPanel.add(box2);

    Box h = Box.createHorizontalBox();
    mainPanel.add(h, BorderLayout.PAGE_END);
    h.add(Box.createHorizontalGlue());
    JButton okButton = new JButton("OK");
    h.add(okButton);
    okButton.setDefaultCapable(true);

    h.add(Box.createHorizontalStrut(10));

    JButton cancelButton = new JButton("Cancel");
    h.add(cancelButton);

    okButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            returnCode = OK_BUTTON;
            dispose();
          }
        });

    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            returnCode = CANCEL_BUTTON;
            dispose();
          }
        });
  }
コード例 #7
0
  public static JPanel createButtonsTable(
      final JTable table, final RowEditableTableModel tableModel, boolean addMnemonics) {
    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

    buttonsPanel.setLayout(new GridBagLayout());
    GridBagConstraints gbConstraints = new GridBagConstraints();
    gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gbConstraints.fill = GridBagConstraints.HORIZONTAL;
    gbConstraints.insets = new Insets(2, 4, 2, 4);

    final JButton addButton = new JButton();
    addButton.setText(
        addMnemonics ? UIBundle.message("row.add") : UIBundle.message("row.add.without.mnemonic"));
    addButton.setDefaultCapable(false);
    buttonsPanel.add(addButton, gbConstraints);

    final JButton removeButton = new JButton();
    removeButton.setText(
        addMnemonics
            ? UIBundle.message("row.remove")
            : UIBundle.message("row.remove.without.mnemonic"));
    removeButton.setDefaultCapable(false);
    buttonsPanel.add(removeButton, gbConstraints);

    final JButton upButton = new JButton();
    upButton.setText(
        addMnemonics
            ? UIBundle.message("row.move.up")
            : UIBundle.message("row.move.up.without.mnemonic"));
    upButton.setDefaultCapable(false);
    buttonsPanel.add(upButton, gbConstraints);

    final JButton downButton = new JButton();
    downButton.setText(
        addMnemonics
            ? UIBundle.message("row.move.down")
            : UIBundle.message("row.move.down.without.mnemonic"));
    downButton.setDefaultCapable(false);
    buttonsPanel.add(downButton, gbConstraints);

    gbConstraints.weighty = 1;
    buttonsPanel.add(new JPanel(), gbConstraints);

    addButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            TableUtil.stopEditing(table);
            tableModel.addRow();
            final int index = tableModel.getRowCount() - 1;
            table.editCellAt(index, 0);
            table.setRowSelectionInterval(index, index);
            table.setColumnSelectionInterval(0, 0);
            table.getParent().repaint();
            final Component editorComponent = table.getEditorComponent();
            if (editorComponent != null) {
              final Rectangle bounds = editorComponent.getBounds();
              table.scrollRectToVisible(bounds);
              editorComponent.requestFocus();
            }
          }
        });

    removeButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            TableUtil.stopEditing(table);
            int index = table.getSelectedRow();
            if (0 <= index && index < tableModel.getRowCount()) {
              tableModel.removeRow(index);
              if (index < tableModel.getRowCount()) {
                table.setRowSelectionInterval(index, index);
              } else {
                if (index > 0) {
                  table.setRowSelectionInterval(index - 1, index - 1);
                }
              }
              updateButtons(table, tableModel, addButton, removeButton, upButton, downButton);
            }

            table.getParent().repaint();
            table.requestFocus();
          }
        });

    upButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            TableUtil.stopEditing(table);
            int index = table.getSelectedRow();
            if (0 < index && index < tableModel.getRowCount()) {
              tableModel.exchangeRows(index, index - 1);
              table.setRowSelectionInterval(index - 1, index - 1);
            }
            table.requestFocus();
          }
        });

    downButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            TableUtil.stopEditing(table);
            int index = table.getSelectedRow();
            if (0 <= index && index < tableModel.getRowCount() - 1) {
              tableModel.exchangeRows(index, index + 1);
              table.setRowSelectionInterval(index + 1, index + 1);
            }
            table.requestFocus();
          }
        });

    table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                updateButtons(table, tableModel, addButton, removeButton, upButton, downButton);
              }
            });
    updateButtons(table, tableModel, addButton, removeButton, upButton, downButton);

    return buttonsPanel;
  }
コード例 #8
0
  /** Initializes all GUI components */
  private void initComponents() {

    mainPanel = new JPanel();
    editPanel = new JPanel();
    editPanelLeft = new JPanel();
    editPanelCenter = new JPanel();
    editPanelRight = new JPanel();
    tablePanel = new JPanel();

    companyIdTextField = new JTextField();
    companyIdTextField.setEditable(false);
    companyNameTextField = new JTextField();
    urlTextField = new JTextField();
    insuranceTypesTextField = new JTextField();
    telephoneTextField = new JTextField();
    percentageTextField = new JTextField();
    percentageTextField.setToolTipText("<html>Only <b>numerical</b> values allowed</html>");
    searchTextField = new JTextField();
    searchTextField.setToolTipText(
        "<html>Use either <b>AND</b> or <b>OR</b> for combined search queries<br>You can also use <b>spaces</b> instead of <b>OR</b></html>");
    generalDescriptionTextField = new JTextField();

    companyIdLabel = new InsuranceCompanyLabel("ID");
    companyNameLabel = new InsuranceCompanyLabel("Company");
    urlLabel = new InsuranceCompanyLabel("Website");
    insuranceTypesLabel = new InsuranceCompanyLabel("Insurance Types");
    telephoneLabel = new InsuranceCompanyLabel("Telephone");
    percentageLabel = new InsuranceCompanyLabel("Broker Percentage");
    searchLabel = new InsuranceCompanyLabel("Search Insurance Types");
    generalDescriptionLabel = new InsuranceCompanyLabel("General Description");
    sortLabel = new InsuranceCompanyLabel("Sorting");

    addInsuranceCompanyButton = new InsuranceCompanyButton("New Insurance Company", 190, 45);
    addInsuranceCompanyButton.setToolTipText(
        "<html>Create a new <b>empty</b> Insurance Company</html>");
    saveInsuranceCompanyButton = new InsuranceCompanyButton("Save Insurance Company", 190, 45);
    saveInsuranceCompanyButton.setToolTipText(
        "<html>Save the <b>selected</b> Insurance Company<br>Hint: Press <b>Enter</b> to quickly save an entry</html>");
    saveInsuranceCompanyButton.setDefaultCapable(true);
    getRootPane()
        .setDefaultButton(
            saveInsuranceCompanyButton); // Set the save button as default button, so quicker
                                         // editing by pressing Enter is possible
    deleteInsuranceCompanyButton = new InsuranceCompanyButton("Delete Insurance Company", 190, 45);
    deleteInsuranceCompanyButton.setToolTipText(
        "<html>Delete the <b>selected</b> Insurance Company</html>");
    clearSearchButton = new InsuranceCompanyButton("x", 40, 35);
    clearSearchButton.setToolTipText("<html>Click to <b>clear</b> the search field</html>");

    String[] sortStrategies = {"ID", "Company Name", "Percentage"};
    sortComboBox = new JComboBox(sortStrategies);

    tableData = new InsuranceCompanyTableModel(model.getInsuranceCompanies());
    insuranceCompaniesTable = new JTable();

    insuranceCompanyScrollPane = new JScrollPane(insuranceCompaniesTable);

    // Set layout and add components to panels
    setLayout(new BorderLayout());
    add(mainPanel, BorderLayout.CENTER);
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(editPanel, BorderLayout.NORTH);
    editPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
    editPanel.setLayout(new BorderLayout());
    editPanel.add(editPanelLeft, BorderLayout.CENTER);
    editPanelLeft.setBorder(new EmptyBorder(0, 0, 5, 15));
    editPanelLeft.setLayout(new GridLayout(4, 4, 5, 0));
    editPanelLeft.add(companyIdLabel);
    editPanelLeft.add(companyNameLabel);
    editPanelLeft.add(urlLabel);
    editPanelLeft.add(telephoneLabel);
    editPanelLeft.add(companyIdTextField);
    editPanelLeft.add(companyNameTextField);
    editPanelLeft.add(urlTextField);
    editPanelLeft.add(telephoneTextField);
    editPanelLeft.add(percentageLabel);
    editPanelLeft.add(searchLabel);
    editPanelLeft.add(new JLabel());
    editPanelLeft.add(sortLabel);
    editPanelLeft.add(percentageTextField);
    editPanelLeft.add(searchTextField);
    Container searchBox = Box.createVerticalBox();
    searchBox.add(clearSearchButton);
    editPanelLeft.add(searchBox);
    editPanelLeft.add(sortComboBox);
    editPanel.add(editPanelRight, BorderLayout.EAST);
    Container box = Box.createVerticalBox();
    box.add(saveInsuranceCompanyButton);
    box.add(Box.createVerticalStrut(5));
    box.add(addInsuranceCompanyButton);
    box.add(Box.createVerticalStrut(5));
    box.add(deleteInsuranceCompanyButton);
    editPanelRight.add(box);
    editPanel.add(editPanelCenter, BorderLayout.SOUTH);
    editPanelCenter.setLayout(new GridLayout(4, 1));
    editPanelCenter.add(insuranceTypesLabel);
    editPanelCenter.add(insuranceTypesTextField);
    editPanelCenter.add(generalDescriptionLabel);
    editPanelCenter.add(generalDescriptionTextField);
    mainPanel.add(tablePanel, BorderLayout.CENTER);
    tablePanel.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createEmptyBorder(10, 10, 10, 10), "Insurance Companies Overview"));
    tablePanel.setLayout(new BorderLayout());
    tablePanel.add(insuranceCompanyScrollPane, BorderLayout.CENTER);

    setMinimumSize(new Dimension(800, 600));
    setPreferredSize(new Dimension(900, 600));
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
  }