public static void main(String[] args) {
    final JPopupMenu menu = new JPopupMenu();
    menu.setLayout(new GridLayout(0, 3, 5, 5));

    final MenuedButton button = new MenuedButton("Icons", menu);

    for (int i = 0; i < 9; i++) {
      // replace "print.gif" with your own image
      final JLabel label = new JLabel("" + i); // new ImageIcon("resources/images/print.gif") );
      label.addMouseListener(
          new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
              button.getMainButton().setIcon(label.getIcon());
              menu.setVisible(false);
            }
          });
      menu.add(label);
    }

    JFrame frame = new JFrame("Button Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(new JLabel("Click Arrow Button To Show Popup"), BorderLayout.NORTH);
    frame.getContentPane().add(button, BorderLayout.CENTER);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
  private void helpButtonActionPerformed(java.awt.event.ActionEvent evt) {
    JPopupMenu jp = new JPopupMenu();

    JMenuItem mi = new JMenuItem("Help"); // No i18n
    JPanel panel = new JPanel();

    String msgTxt =
        "<html>Drops redundant events/alerts. <br>The suppressed/dropped Events/alerts will not <br>be added to the database. <br>You can choose to suppress all events/alerts <br>or only those that occur after a <br>certain period of time. <br>Refer Admin Guide for details.</html>"; // No i18n

    /*JTextArea ep = new JTextArea();
    ep.setColumns(20);
    ep.setLineWrap(true);
    ep.setRows(10);
    ep.setBackground(new java.awt.Color(200, 200, 200));
    ep.setWrapStyleWord(true);*/
    JLabel ep = new JLabel();
    ep.setSize(300, 200);
    ep.setText(msgTxt);
    panel.add(ep);

    mi.setLayout(new BorderLayout());
    mi.setPreferredSize(panel.getPreferredSize());
    mi.setFocusPainted(false);
    mi.add(panel, BorderLayout.CENTER);
    jp.setLayout(new BorderLayout());
    jp.add(mi, BorderLayout.CENTER);
    jp.show(helpButton, -60, -60);
  }
예제 #3
0
  public MenuPanelOrderPanel(MenuPanel in) {

    menuPanel = in;
    border = new BorderLayout();
    setLayout(border);
    setPreferredSize(new Dimension(280, 800));

    taxModifier = 1.05;
    finalModifier = 0;
    finalPercentModifier = 1;

    topPanel = new JPanel();
    midPanel = new JPanel();
    bottomPanel = new JPanel();

    // set up topPanel components
    topPanelLabel = new JLabel("Reset all");
    topPanelLabel.addMouseListener(this);
    topPanel.setBackground(Color.LIGHT_GRAY);
    // set up midPanel components
    midLayout = new GridLayout(16, 1);
    midPanel.setLayout(midLayout);
    orderLabel = new JLabel[300];
    itemCountOfLabel = new int[300];
    itemPriceOfLabel = new double[300];
    itemNameOfLabel = new String[300];
    itemPriceModifier = new double[300];
    itemOriginalPrice = new double[300];
    counter = 0;
    popup = new JPopupMenu();
    discountPopup = new JPopupMenu();
    countPopup = new JPopupMenu();
    midPanel.setBackground(Color.WHITE);
    // set up bottomPanel components
    bottomLayout = new GridLayout(3, 2);
    bottomPanel.setLayout(bottomLayout);
    costLabel = new JLabel("Cost: .00");
    costLabel.addMouseListener(this);
    paidLabel = new JLabel("Paid: .00");
    changeLabel = new JLabel("Change: .00");
    costTaxOnlyLabel = new JLabel("Tax: .00");
    costAfterTaxLabel = new JLabel("Total: .00");
    // set up popup components
    popupLayout = new GridLayout(2, 2);
    popup.setLayout(popupLayout);
    removeButton = new JButton("Remove");
    removeButton.addActionListener(this);
    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(this);
    discountButton = new JButton("Discount");
    discountButton.addActionListener(this);
    countButton = new JButton("Count");
    countButton.addActionListener(this);
    // set up discountPopup components
    itemDiscountPopupLabel = new JLabel("Discount: ");
    itemDiscountPopupString = "";
    discountKeypadPanel = new JPanel();
    percentagePanel = new JPanel();
    resetPanel = new JPanel();

    discountLayout = new BorderLayout();
    discountPopup.setLayout(discountLayout);
    discountKeypadLayout = new GridLayout(4, 3);
    discountKeypadPanel.setLayout(discountKeypadLayout);
    percentLayout = new GridLayout(2, 1);
    percentagePanel.setLayout(percentLayout);
    resetPanel.setLayout(percentLayout);

    discountButton0 = new JButton("0");
    discountButton0.setPreferredSize(new Dimension(90, 90));
    discountButton1 = new JButton("1");
    discountButton2 = new JButton("2");
    discountButton3 = new JButton("3");
    discountButton4 = new JButton("4");
    discountButton5 = new JButton("5");
    discountButton6 = new JButton("6");
    discountButton7 = new JButton("7");
    discountButton8 = new JButton("8");
    discountButton9 = new JButton("9");
    okDiscountButton = new JButton("$");
    clearDiscountButton = new JButton("Cancel");
    percentDiscountButton = new JButton("%");
    resetDiscountButton = new JButton("Reset");
    discountButton0.addActionListener(this);
    discountButton1.addActionListener(this);
    discountButton2.addActionListener(this);
    discountButton3.addActionListener(this);
    discountButton4.addActionListener(this);
    discountButton5.addActionListener(this);
    discountButton6.addActionListener(this);
    discountButton7.addActionListener(this);
    discountButton8.addActionListener(this);
    discountButton9.addActionListener(this);
    okDiscountButton.addActionListener(this);
    clearDiscountButton.addActionListener(this);
    percentDiscountButton.addActionListener(this);
    resetDiscountButton.addActionListener(this);
    percentagePanel.add(okDiscountButton);
    percentagePanel.add(percentDiscountButton);
    resetPanel.add(resetDiscountButton);
    resetPanel.add(clearDiscountButton);

    discountKeypadPanel.add(discountButton1);
    discountKeypadPanel.add(discountButton2);
    discountKeypadPanel.add(discountButton3);
    discountKeypadPanel.add(discountButton4);
    discountKeypadPanel.add(discountButton5);
    discountKeypadPanel.add(discountButton6);
    discountKeypadPanel.add(discountButton7);
    discountKeypadPanel.add(discountButton8);
    discountKeypadPanel.add(discountButton9);
    discountKeypadPanel.add(percentagePanel);
    discountKeypadPanel.add(discountButton0);
    discountKeypadPanel.add(resetPanel);
    // set up countPopup components
    itemCountPopupLabel = new JLabel("Item count: ");
    itemCountPopupString = "";
    countKeypadPanel = new JPanel();

    countLayout = new BorderLayout();
    countPopup.setLayout(countLayout);
    keypadLayout = new GridLayout(4, 3);
    countKeypadPanel.setLayout(keypadLayout);

    countButton0 = new JButton("0");
    countButton0.setPreferredSize(new Dimension(90, 90));
    countButton1 = new JButton("1");
    countButton2 = new JButton("2");
    countButton3 = new JButton("3");
    countButton4 = new JButton("4");
    countButton5 = new JButton("5");
    countButton6 = new JButton("6");
    countButton7 = new JButton("7");
    countButton8 = new JButton("8");
    countButton9 = new JButton("9");
    okCountButton = new JButton("Ok");
    clearCountButton = new JButton("Cancel");
    countButton0.addActionListener(this);
    countButton1.addActionListener(this);
    countButton2.addActionListener(this);
    countButton3.addActionListener(this);
    countButton4.addActionListener(this);
    countButton5.addActionListener(this);
    countButton6.addActionListener(this);
    countButton7.addActionListener(this);
    countButton8.addActionListener(this);
    countButton9.addActionListener(this);
    okCountButton.addActionListener(this);
    clearCountButton.addActionListener(this);

    countKeypadPanel.add(countButton1);
    countKeypadPanel.add(countButton2);
    countKeypadPanel.add(countButton3);
    countKeypadPanel.add(countButton4);
    countKeypadPanel.add(countButton5);
    countKeypadPanel.add(countButton6);
    countKeypadPanel.add(countButton7);
    countKeypadPanel.add(countButton8);
    countKeypadPanel.add(countButton9);
    countKeypadPanel.add(okCountButton);
    countKeypadPanel.add(countButton0);
    countKeypadPanel.add(clearCountButton);

    // add topPanel components
    topPanel.add(topPanelLabel);
    // add midPanel components
    // add bottomPanel components
    bottomPanel.add(costLabel);
    bottomPanel.add(paidLabel);
    bottomPanel.add(costTaxOnlyLabel);
    bottomPanel.add(changeLabel);
    bottomPanel.add(costAfterTaxLabel);
    // add popup components
    popup.add(removeButton);
    removeButton.setPreferredSize(new Dimension(80, 80));
    popup.add(discountButton);
    popup.add(countButton);
    popup.add(cancelButton);
    // add discoundPopup components
    discountPopup.add(itemDiscountPopupLabel, BorderLayout.NORTH);
    discountPopup.add(discountKeypadPanel, BorderLayout.CENTER);
    // add countPopup components
    countPopup.add(itemCountPopupLabel, BorderLayout.NORTH);
    countPopup.add(countKeypadPanel, BorderLayout.CENTER);

    printClass = new Print(this);

    add(topPanel, BorderLayout.NORTH);
    add(midPanel, BorderLayout.CENTER);
    add(bottomPanel, BorderLayout.SOUTH);
  }
예제 #4
0
  public static void setPopup(
      final JTextField tf,
      Object[][] obj,
      final JLabel[] labels,
      final int[] tbl_widths_customers,
      String[] col_names) {

    final JPopupMenu popup = new JPopupMenu();
    Dimension d = tf.getSize();
    popup.setLayout(new BorderLayout());

    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    p.setBackground(Color.white);
    JScrollPane pl = new JScrollPane();
    final JTable tbl = new JTable();
    pl.setBorder(null);
    TableRenderer.setModel(tbl, obj, col_names, tbl_widths_customers);
    tbl.getTableHeader().setPreferredSize(new Dimension(0, 0));
    tbl.setBorder(null);
    tbl.setGridColor(new java.awt.Color(204, 204, 204));
    pl.setViewportView(tbl);
    p.add(pl);
    popup.add(p);
    popup.setPopupSize(d.width, 150);
    popup.show(tf, 0, tf.getHeight());
    tf.grabFocus();
    tf.addKeyListener(
        new KeyAdapter() {

          @Override
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DOWN) {
              if (tbl.getRowCount() != 0) {
                tbl.setRowSelectionInterval(0, 0);
                tbl.grabFocus();
              }
            }
          }
        });
    tbl.addKeyListener(
        new KeyAdapter() {

          @Override
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_LEFT) {
              int row = tbl.getSelectedRow();
              tbl.removeRowSelectionInterval(row, row);
              tf.grabFocus();
            }
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
              int row = tbl.getSelectedRow();
              int i = 0;
              for (JLabel lbl : labels) {
                lbl.setText(tbl.getModel().getValueAt(row, i).toString());
                i++;
              }
              String[] output = new String[tbl_widths_customers.length];
              int u = 0;
              for (int y : tbl_widths_customers) {
                output[u] = tbl.getModel().getValueAt(row, u).toString();
                u++;
              }
              tf.grabFocus();
              popup.setVisible(false);
              ok1(output, row);
            }
          }
        });
    tbl.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            int row = tbl.getSelectedRow();
            String[] output = new String[tbl_widths_customers.length];
            int u = 0;
            for (int y : tbl_widths_customers) {
              output[u] = tbl.getModel().getValueAt(row, u).toString();
              u++;
            }
            tf.grabFocus();
            popup.setVisible(false);
            ok1(output, row);
          }
        });
  }
예제 #5
0
  /**
   * Creates a ClickableTooltip with custom show/hide delays
   *
   * @param text The tooltip text
   * @param action The action which should be provided to the user
   * @param startupDelay Delay in ms before the tooltip should be shown
   * @param showTime Delay in ms after which the tooltip vanishes when the cursor moved away from
   *     the component or the tooltip area
   */
  public ClickableTooltip(
      final String text, final Action action, final int startupDelay, final int showTime) {
    Color c = UIUtilities.TOOLTIP_COLOR;
    Font f = (FontUIResource) UIManager.get("ToolTip.font");

    popupMenu = new JPopupMenu();
    popupMenu.setLayout(new BoxLayout(popupMenu, BoxLayout.PAGE_AXIS));
    popupMenu.setBorder(BorderFactory.createEmptyBorder(INSETS, INSETS, INSETS, INSETS));
    popupMenu.setBackground(c);
    popupMenu.setFont(f);

    if (text != null) {
      JLabel desc = new JLabel(text);
      desc.setBackground(c);
      desc.setFont(f);
      popupMenu.add(desc);
    }

    final JLabel label = new JLabel();
    label.setForeground(LINK_COLOR);
    label.setBackground(c);
    label.setFont(f);
    label.setText((String) action.getValue(Action.NAME));
    label.addMouseListener(
        new MouseAdapter() {
          Cursor defaultCursor = null;

          public void mouseReleased(MouseEvent e) {
            action.actionPerformed(
                new ActionEvent(this, -1, (String) action.getValue(Action.ACTION_COMMAND_KEY)));
            // if the user clicks on the 'link' remove tooltip
            popupMenu.setVisible(false);
          }

          @Override
          public void mouseEntered(MouseEvent e) {
            defaultCursor = label.getCursor();
            label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            hideTimer.stop();
          }

          @Override
          public void mouseExited(MouseEvent e) {
            if (defaultCursor != null) {
              label.setCursor(defaultCursor);
            }
            hideTimer.restart();
          }
        });

    popupMenu.add(label);

    showTimer =
        new Timer(
            startupDelay,
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent arg0) {
                popupMenu.show(component, location.x, location.y);
                showTimer.stop();
              }
            });

    hideTimer =
        new Timer(
            startupDelay + showTime,
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent arg0) {
                popupMenu.setVisible(false);
                hideTimer.stop();
              }
            });
  }