Esempio n. 1
0
  public MainPanel() {
    super(new BorderLayout());
    JPanel p = new JPanel(new GridLayout(2, 1));
    final JComboBox<String> c0 = makeComboBox(true, false);
    final JComboBox<String> c1 = makeComboBox(false, false);
    final JComboBox<String> c2 = makeComboBox(true, true);
    final JComboBox<String> c3 = makeComboBox(false, true);

    p.add(makeTitlePanel("setEditable(false)", Arrays.asList(c0, c1)));
    p.add(makeTitlePanel("setEditable(true)", Arrays.asList(c2, c3)));
    p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    add(p, BorderLayout.NORTH);
    add(
        new JButton(
            new AbstractAction("add") {
              @Override
              public void actionPerformed(ActionEvent e) {
                String str = new Date().toString();
                for (JComboBox<String> c : Arrays.asList(c0, c1, c2, c3)) {
                  MutableComboBoxModel<String> m = (MutableComboBoxModel<String>) c.getModel();
                  m.insertElementAt(str, m.getSize());
                }
              }
            }),
        BorderLayout.SOUTH);
    setPreferredSize(new Dimension(320, 240));
  }
Esempio n. 2
0
 public ButtonsRenderer(RemoveButtonComboBox<E> comboBox) {
   super(new BorderLayout(0, 0));
   this.comboBox = comboBox;
   label.setOpaque(false);
   setOpaque(true);
   add(label);
   deleteButton.setBorder(BorderFactory.createEmptyBorder());
   deleteButton.setFocusable(false);
   deleteButton.setRolloverEnabled(false);
   deleteButton.setContentAreaFilled(false);
   add(deleteButton, BorderLayout.EAST);
 }
Esempio n. 3
0
 public MainPanel() {
   super(new BorderLayout());
   initComboBox(combo01);
   int g = 5;
   JPanel p = new JPanel(new GridLayout(2, 2, g, g));
   p.add(combo00);
   p.add(new JLabel("<- default"));
   p.add(combo01);
   p.add(new JLabel("<- RightPopupMenuListener"));
   setBorder(BorderFactory.createEmptyBorder(g, g, g, g));
   add(p, BorderLayout.NORTH);
   setPreferredSize(new Dimension(320, 240));
 }
Esempio n. 4
0
 private JComponent makeTitlePanel(String title, List<? extends JComponent> list) {
   JPanel p = new JPanel(new GridBagLayout());
   p.setBorder(BorderFactory.createTitledBorder(title));
   GridBagConstraints c = new GridBagConstraints();
   c.fill = GridBagConstraints.HORIZONTAL;
   c.insets = new Insets(5, 5, 5, 5);
   c.weightx = 1d;
   c.gridy = 0;
   for (JComponent cmp : list) {
     p.add(cmp, c);
     c.gridy++;
   }
   return p;
 }
Esempio n. 5
0
  private static JComponent makeUI() {
    // final JProgressBar progressBar = new JProgressBar(SwingConstants.VERTICAL);
    final JProgressBar progressBar = new JProgressBar();
    progressBar.setOpaque(false);
    progressBar.setUI(new GradientPalletProgressBarUI());

    GridBagConstraints c = new GridBagConstraints();
    JPanel p = new JPanel(new GridBagLayout());
    p.setBorder(BorderFactory.createEmptyBorder(32, 8, 0, 8));

    c.gridheight = 1;
    c.gridwidth = 1;
    c.gridy = 0;

    c.gridx = 0;
    c.insets = new Insets(0, 0, 0, 4);
    c.weightx = 1d;
    c.fill = GridBagConstraints.HORIZONTAL;
    p.add(progressBar, c);

    c.gridx = 1;
    c.weightx = 0d;
    p.add(
        new JButton(
            new AbstractAction("Start") {
              @Override
              public void actionPerformed(ActionEvent e) {
                final JButton b = (JButton) e.getSource();
                b.setEnabled(false);
                SwingWorker<Void, Void> worker =
                    new Task() {
                      @Override
                      public void done() {
                        if (b.isDisplayable()) {
                          b.setEnabled(true);
                        }
                      }
                    };
                worker.addPropertyChangeListener(new ProgressListener(progressBar));
                worker.execute();
              }
            }),
        c);
    return p;
  }
Esempio n. 6
0
  /**
   * Create a component that will replace the spinner models value with the object returned by
   * <code>spinner.getNextValue</code>. By default the <code>nextButton</code> is a JButton who's
   * <code>ActionListener</code> updates it's <code>JSpinner</code> ancestors model. If a nextButton
   * isn't needed (in a subclass) then override this method to return null.
   *
   * @return a component that will replace the spinners model with the next value in the sequence,
   *     or null
   * @see #installUI
   * @see #createPreviousButton
   */
  protected Component createNextButton() {
    Component tmpButton = super.createNextButton();

    if (tmpButton instanceof JButton) {
      JButton result = new ArrowButton(SwingConstants.NORTH);
      ((ArrowButton) result).setDrawBottomBorder(false);

      result.setBorder(
          BorderFactory.createMatteBorder(1, 1, 0, 1, UIManager.getColor("Button.borderColor")));
      ActionListener al[] = ((JButton) tmpButton).getActionListeners();
      for (int i = 0; i < al.length; i++) result.addActionListener(al[i]);

      MouseListener ml[] = ((JButton) tmpButton).getMouseListeners();
      for (int i = 0; i < ml.length; i++) result.addMouseListener(ml[i]);

      return result;
    } else return tmpButton;
  }
    Title(String title) {
      super();
      setText(title);
      setHorizontalAlignment(SwingConstants.CENTER);
      setBorder(
          BorderFactory.createBevelBorder(
              BevelBorder.RAISED,
              UIManager.getColor("activeCaptionBorder"),
              UIManager.getColor("inactiveCaptionBorder")));

      // Forward mouse events to titlebar for moves.
      addMouseMotionListener(
          new MouseMotionListener() {
            public void mouseDragged(MouseEvent e) {
              forwardEventToParent(e);
            }

            public void mouseMoved(MouseEvent e) {
              forwardEventToParent(e);
            }
          });
      addMouseListener(
          new MouseListener() {
            public void mouseClicked(MouseEvent e) {
              forwardEventToParent(e);
            }

            public void mousePressed(MouseEvent e) {
              forwardEventToParent(e);
            }

            public void mouseReleased(MouseEvent e) {
              forwardEventToParent(e);
            }

            public void mouseEntered(MouseEvent e) {
              forwardEventToParent(e);
            }

            public void mouseExited(MouseEvent e) {
              forwardEventToParent(e);
            }
          });
    }