コード例 #1
0
ファイル: JCheckBox2.java プロジェクト: cccggglll888/oswing
  @Override
  public void itemStateChanged(ItemEvent e) {
    //		e.getItem();//状态
    System.out.println("e.getItem()           === " + e.getItem());
    //		e.paramString();//状态
    System.out.println("e.paramString()       === " + e.paramString());
    //		e.getItemSelectable();//选中对象,相当于是getSource
    System.out.println("e.getItemSelectable() === " + e.getItemSelectable());
    //		e.getStateChange();
    System.out.println("e.getStateChange()    === " + e.getStateChange());

    if (e.getStateChange() == ItemEvent.SELECTED) {
      if (e.getSource() == c4) {
        c4.setIcon(new ImageIcon(ClassLoader.getSystemResource("img2.jpg")));
      }
      if (e.getSource() == c5) {
        c5.setIcon(new ImageIcon(ClassLoader.getSystemResource("img2.jpg")));
      }
    } else {
      if (e.getSource() == c4) {
        c4.setIcon(new ImageIcon(ClassLoader.getSystemResource("img1.jpg")));
      }
      if (e.getSource() == c5) {
        c5.setIcon(new ImageIcon(ClassLoader.getSystemResource("img1.jpg")));
      }
    }
  }
コード例 #2
0
    @Override
    public Component getTreeCellRendererComponent(
        JTree tree,
        Object value,
        boolean sel,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {
      super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

      if (!(value instanceof File)) {
        labelRenderer.getTreeCellRendererComponent(tree, value, sel, expanded, false, row, false);
        labelRenderer.setIcon(null);
        return labelRenderer;
      }

      File file = (File) value;
      checkBox.setText(RecursiveLibraryDirectoryPanel.this.getText(file));
      // setColors(compTemp, tree, tree.getPathForRow(row), checkBox, sel);
      checkBox.setBackground(this.getBackground());
      checkBox.setForeground(this.getForeground());

      if (isExcluded(file)) {
        checkBox.setSelected(false);
        checkBox.setIcon(null);
      } else if (isFullyIncluded(file)) {
        checkBox.setSelected(true);
        checkBox.setIcon(null);
      } else {
        checkBox.setSelected(true);
        checkBox.setIcon(partiallyIncludedIcon);
      }
      return checkBox;
    }
コード例 #3
0
ファイル: GUILogin.java プロジェクト: charleshans/PQQ
 @Override
 public void mouseExited(MouseEvent e) {
   Object obj = e.getSource();
   if (obj instanceof JButton) {
     JButton jbtn = (JButton) obj;
     if (jbtn == jsetup) {
       jbtn.setIcon(setup[0]);
     } else if (jbtn == jclose) {
       jbtn.setIcon(close[0]);
     } else if (jbtn == jmin) {
       jbtn.setIcon(min[0]);
     } else if (jbtn == jlogin) {
       jbtn.setIcon(loginImages[0]);
     }
   } else if (obj instanceof JLabel) {
     JLabel jbl = (JLabel) obj;
     if (jbl == register) {
       jbl.setIcon(regs[0]);
     } else if (jbl == minaFind) {
       jbl.setIcon(mina[0]);
     } else if (jbl == swit) {
       jbl.setIcon(swits[0]);
     } else if (jbl == right) {
       jbl.setIcon(rights[0]);
     }
   } else if (obj instanceof JCheckBox) {
     JCheckBox jcb = (JCheckBox) obj;
     if (!jcb.isSelected()) jcb.setIcon(remPwds[0]);
     else jcb.setSelectedIcon(remPwds[3]);
   }
 }
コード例 #4
0
  /**
   * Create the legend
   *
   * <p>If basePanel is non-null, the legend panel replaces the contents of that panel.
   */
  private JPanel createLegendPanel(JPanel basePanel) {
    final JPanel panel;
    if (basePanel != null) {
      basePanel.removeAll();
      basePanel.setLayout(new GridBagLayout());
      panel = basePanel;
    } else {
      panel = new JPanel(new GridBagLayout());
    }

    panel.setBorder(BorderFactory.createTitledBorder(I18n.tr("Legend")));
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(0, 4, 0, 6);

    JCheckBox checkBox = new JCheckBox();
    checkBox.setSelected(true);
    panel.add(createIconLabel(checkBox), gbc);

    MultiLineLabel label =
        new MultiLineLabel(I18n.tr("Folder and subfolders are included in the Library."), true);
    GridBagConstraints labelGbc = new GridBagConstraints();
    labelGbc.anchor = GridBagConstraints.WEST;
    labelGbc.fill = GridBagConstraints.HORIZONTAL;
    labelGbc.gridwidth = GridBagConstraints.REMAINDER;
    labelGbc.gridx = 1;
    labelGbc.weightx = 1;

    panel.add(label, labelGbc);

    checkBox.setSelected(false);
    gbc.gridy = 1;
    panel.add(createIconLabel(checkBox), gbc);

    label =
        new MultiLineLabel(
            I18n.tr("Folder is not included and no subfolders are included in the Library."), true);
    labelGbc.gridy = 1;
    panel.add(label, labelGbc);

    checkBox.setIcon(partiallyIncludedIcon);
    gbc.gridy = 2;
    gbc.insets = new Insets(0, 6, 0, 0);
    panel.add(createIconLabel(checkBox), gbc);

    label =
        new MultiLineLabel(
            I18n.tr("Folder\'s files and some subfolders are included in the Library."), true);
    labelGbc.gridy = 2;
    gbc.insets = null;
    panel.add(label, labelGbc);

    return panel;
  }
コード例 #5
0
ファイル: GUILogin.java プロジェクト: charleshans/PQQ
 @Override
 public void mousePressed(MouseEvent e) {
   Object obj = e.getSource();
   if (obj instanceof JButton) {
     JButton jbtn = (JButton) obj;
     if (jbtn == jsetup) {
       jbtn.setIcon(setup[2]);
     } else if (jbtn == jclose) {
       jbtn.setIcon(close[2]);
       System.exit(0);
     } else if (jbtn == jmin) {
       jbtn.setIcon(min[2]);
       // jdk7 setType
       mainLogin.setExtendedState(JFrame.ICONIFIED);
     } else if (jbtn == jlogin) {
       jbtn.setIcon(loginImages[2]);
     }
   } else if (obj instanceof JLabel) {
     JLabel jbl = (JLabel) obj;
     if (jbl == register) {
       jbl.setIcon(regs[2]);
     } else if (jbl == minaFind) {
       jbl.setIcon(mina[2]);
     } else if (jbl == swit) {
       jbl.setIcon(swits[2]);
     } else if (jbl == right) {
       jbl.setIcon(rights[2]);
     }
   } else if (obj instanceof JCheckBox) {
     JCheckBox jcb = (JCheckBox) obj;
     if (!jcb.isSelected()) {
       jcb.doClick();
       jcb.setSelected(true);
       jcb.setSelectedIcon(remPwds[2]);
     } else {
       jcb.doClick();
       jcb.setSelected(false);
       jcb.setIcon(remPwds[1]);
     }
   }
 }
コード例 #6
0
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      JComponent renderer = null;

      if (value instanceof Icon) {
        Icon icon = (Icon) value;
        // Hack to fix problem where some plaf Icons cast the component to
        // various component classes. yikes!  not very re-usable icons :(
        String className = (String) table.getValueAt(row, UIDefaultsTableModel.TYPE_COLUMN);
        if (className.contains("BasicIconFactory$RadioButtonMenuItemIcon")
            || className.contains("BasicIconFactory$CheckBoxMenuItemIcon")
            || className.contains("OceanTheme$IFIcon")
            || className.contains("MotifIconFactory$RadioButtonIcon")
            || className.contains("MotifIconFactory$CheckBoxIcon")
            || className.contains("MotifIconFactory$MenuArrowIcon")
            || className.contains("WindowsIconFactory$FrameButtonIcon")
            || className.contains("WindowsIconFactory$RadioButtonIcon")) {
          buttonIconRenderer.setIcon(icon);
          buttonIconRenderer.setSelected(true);
          renderer = buttonIconRenderer;

        } else if (className.contains("MetalIconFactory$RadioButtonIcon")) {
          radioIconRenderer.setIcon(icon);
          renderer = radioIconRenderer;

        } else if (className.contains("MetalIconFactory$RadioButtonMenuItemIcon")
            || className.contains("MetalIconFactory$CheckBoxMenuItemIcon")
            || className.contains("MetalIconFactory$MenuArrowIcon")
            || className.contains("MetalIconFactory$MenuItemArrowIcon")) {
          menuItemIconRenderer.setIcon(icon);
          menuItemIconRenderer.setSelected(true);
          renderer = menuItemIconRenderer;

        } else if (className.contains("MetalIconFactory$CheckBoxIcon")
            || className.contains("WindowsIconFactory$CheckBoxIcon")) {
          checkboxIconRenderer.setIcon(icon);
          checkboxIconRenderer.setSelected(true);
          renderer = checkboxIconRenderer;
        }
      }

      if (renderer != null) {
        // special hack renderer for icons needs to be colorized because
        // it doesn't extend RowRenderer
        setColors(table, row, isSelected);
        setBorder(renderer, hasFocus, isSelected);

      } else {
        // renderer == this
        renderer =
            (JComponent)
                super.getTableCellRendererComponent(
                    table, value, isSelected, hasFocus, row, column);
        if (value instanceof Color) {
          Color color = (Color) value;
          float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);

          setIcon(ColorIcon.getIcon(color));
          setText(
              "RGB="
                  + color.getRed()
                  + ","
                  + color.getGreen()
                  + ","
                  + color.getBlue()
                  + "  "
                  + "HSB="
                  + String.format("%.0f%n", hsb[0] * 360)
                  + ","
                  + String.format("%.3f%n", hsb[1])
                  + ","
                  + String.format("%.3f%n", hsb[2]));

        } else if (value instanceof Font) {
          Font font = (Font) value;
          setFont(font);
          setText(font.getFontName() + " size=" + font.getSize2D());
          setIcon(null);

        } else if (value instanceof Icon) {
          setIcon((Icon) value);
          setText("");
        }
      }
      return renderer;
    }
コード例 #7
0
 public void decorateLargeCheckBox(JCheckBox box) {
   box.setIcon(largeBox);
   box.setSelectedIcon(largeBoxChecked);
   box.setOpaque(false);
   box.setFocusPainted(false);
 }