コード例 #1
0
 public void actionPerformed(ActionEvent ae) {
   String cname = nameF.getText().trim();
   int state = conditions[stateC.getSelectedIndex()];
   try {
     if (isSpecialCase(cname)) {
       handleSpecialCase(cname, state);
     } else {
       JComponent comp = (JComponent) Class.forName(cname).newInstance();
       ComponentUI cui = UIManager.getUI(comp);
       cui.installUI(comp);
       results.setText("Map entries for " + cname + ":\n\n");
       if (inputB.isSelected()) {
         loadInputMap(comp.getInputMap(state), "");
         results.append("\n");
       }
       if (actionB.isSelected()) {
         loadActionMap(comp.getActionMap(), "");
         results.append("\n");
       }
       if (bindingB.isSelected()) {
         loadBindingMap(comp, state);
       }
     }
   } catch (ClassCastException cce) {
     results.setText(cname + " is not a subclass of JComponent.");
   } catch (ClassNotFoundException cnfe) {
     results.setText(cname + " was not found.");
   } catch (InstantiationException ie) {
     results.setText(cname + " could not be instantiated.");
   } catch (Exception e) {
     results.setText("Exception found:\n" + e);
     e.printStackTrace();
   }
 }
コード例 #2
0
 @Override
 public Component prepareEditor(TableCellEditor editor, int row, int column) {
   Component c = super.prepareEditor(editor, row, column);
   if (c instanceof JCheckBox) {
     ((JCheckBox) c).setBackground(getSelectionBackground());
   }
   return c;
 }
コード例 #3
0
 private void handleSpecialCase(String cname, int condition) {
   Component comp = null;
   JComponent mapComp = null;
   try {
     if (cname.equals("javax.swing.JApplet")
         || cname.equals("javax.swing.JDialog")
         || cname.equals("javax.swing.JFrame")
         || cname.equals("javax.swing.JWindow")) {
       comp = (Component) Class.forName(cname).newInstance();
       mapComp = (JComponent) ((JApplet) comp).getLayeredPane();
       results.setText("Map entries for " + cname + " (delegated to JRootPane):\n\n");
     } else if (cname.equals("javax.swing.JInternalFrame")) {
       JDesktopPane jdp = new JDesktopPane();
       JInternalFrame jif = new JInternalFrame("Demo");
       jif.setVisible(true);
       jdp.add(jif);
       mapComp = jif;
     }
     if (inputB.isSelected()) {
       loadInputMap(mapComp.getInputMap(condition), "");
       results.append("\n");
     }
     if (actionB.isSelected()) {
       loadActionMap(mapComp.getActionMap(), "");
       results.append("\n");
     }
     if (bindingB.isSelected()) {
       loadBindingMap(mapComp, condition);
     }
   } catch (ClassCastException cce) {
     results.setText(cname + " is not a subclass of JComponent.");
   } catch (ClassNotFoundException cnfe) {
     results.setText(cname + " was not found.");
   } catch (InstantiationException ie) {
     results.setText(cname + " could not be instantiated.");
   } catch (Exception e) {
     results.setText("Exception found:\n" + e);
     e.printStackTrace();
   }
 }
コード例 #4
0
  @Override
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    getModel().setRollover(highlighter.isHighlightableCell(row, column));

    if (isSelected) {
      setForeground(table.getSelectionForeground());
      super.setBackground(table.getSelectionBackground());
    } else {
      setForeground(table.getForeground());
      setBackground(table.getBackground());
      // setBackground(row % 2 == 0 ? table.getBackground() : Color.WHITE); //Nimbus
    }
    setSelected(Objects.equals(value, Boolean.TRUE));
    return this;
  }