コード例 #1
0
  public void setUseFlatUI(boolean b) {
    main.setContentAreaFilled(!b);
    main.setFocusPainted(!b);
    main.setBorderPainted(!b);
    main.setMargin(new Insets(1, 1, 1, 1));

    popper.setContentAreaFilled(!b);
    popper.setFocusPainted(!b);
    popper.setBorderPainted(!b);
    popper.setMargin(new Insets(1, 1, 1, 1));

    setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    setOpaque(false);

    MouseAdapter ma =
        new MouseAdapter() {
          public void mouseEntered(MouseEvent e) {
            main.setContentAreaFilled(true);
            main.setBackground(new Color(216, 240, 254));
            // m.getMainButton().setForeground( Color.black );
            setBorder(new LineBorder(new Color(200, 200, 200), 1));
            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

            popper.setBackground(new Color(242, 242, 242));
            popper.setContentAreaFilled(true);
            popper.setBorder(menu.getBorder());
          }

          public void mouseExited(MouseEvent e) {
            main.setContentAreaFilled(false);
            //	c.setForeground( Color.black );
            setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
            setCursor(Cursor.getDefaultCursor());

            popper.setContentAreaFilled(false);
            popper.setBorder(null);
          }
        };

    main.addMouseListener(ma);
    popper.addMouseListener(ma);
  }
コード例 #2
0
  public void createButtons(String text, Icon icon) {
    if (main == null) {
      main = new JButton(text, icon);

      if (text == null) {
        main.setMargin(new Insets(0, 0, 0, 0));
      }
    }

    // main.setFont( new Font("Verdana", Font.PLAIN, 11) );
    ImageIcon img = new ImageIcon("resources/images/popicon.gif");
    popper =
        new JButton(/*img*/ ) {

          public void paintComponent(Graphics g) {
            super.paintComponent(g);

            Graphics2D g2 = (Graphics2D) g;
            int width = getWidth(), height = getHeight();
            int midWidth = width / 2, midHeight = height / 2;

            int[] xpoints = {midWidth - 4, midWidth, midWidth + 4};
            int[] ypoints = {midHeight - 1, midHeight + 3, midHeight - 1};

            if (ARROW_DIRECTION == FORWARD) {
              xpoints = new int[] {midWidth - 3, midWidth - 3, midWidth + 2};
              ypoints = new int[] {midHeight - 4, midHeight + 4, midHeight};
            }

            g2.setColor(getPopperArrowColor());
            g2.fill(new Polygon(xpoints, ypoints, 3));
          }
        };

    // popper.setPreferredSize( new Dimension(img.getImage().getWidth(this) + 10,

    popper.addActionListener(this);

    setBorder(null);
    // setLayout( new BoxLayout(this, BoxLayout.X_AXIS) );
    layoutComponents();
  }