private static void setDescendantsEnabledIn(JComponent root, boolean b) { for (Component child : root.getComponents()) { child.setEnabled(b); if (child instanceof JComponent) { setDescendantsEnabledIn((JComponent) child, b); } } }
@Override public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { final Component result = super.prepareRenderer(renderer, row, column); final boolean selected = myExpandableItemsHandler.getExpandedItems().contains(new TableCell(row, column)); // Fix GTK background if (UIUtil.isUnderGTKLookAndFeel()) { UIUtil.changeBackGround(this, UIUtil.getTreeTextBackground()); } if (isTableDecorationSupported() && isStriped() && result instanceof JComponent) { final Color bg = row % 2 == 1 ? getBackground() : DECORATED_ROW_BG_COLOR; final JComponent c = (JComponent) result; final boolean cellSelected = isCellSelected(row, column); if (!cellSelected || (!hasFocus() && !getSelectionBackground().equals(c.getBackground()))) { c.setOpaque(true); c.setBackground(bg); for (Component child : c.getComponents()) { child.setBackground(bg); } } } if (!selected) return result; return new JComponent() { { add(result); setOpaque(false); setLayout( new AbstractLayoutManager() { @Override public Dimension preferredLayoutSize(Container parent) { return result.getPreferredSize(); } @Override public void layoutContainer(Container parent) { Dimension size = parent.getSize(); Insets i = parent.getInsets(); Dimension pref = result.getPreferredSize(); result.setBounds( i.left, i.top, Math.max(pref.width, size.width - i.left - i.right), size.height - i.top - i.bottom); } }); } }; }
public static void main(String args[]) { JComponent ch = new JComponent() {}; ch.getAccessibleContext(); ch.isFocusTraversable(); ch.setEnabled(false); ch.setEnabled(true); ch.requestFocus(); ch.requestFocusInWindow(); ch.getPreferredSize(); ch.getMaximumSize(); ch.getMinimumSize(); ch.contains(1, 2); Component c1 = ch.add(new Component() {}); Component c2 = ch.add(new Component() {}); Component c3 = ch.add(new Component() {}); Insets ins = ch.getInsets(); ch.getAlignmentY(); ch.getAlignmentX(); ch.getGraphics(); ch.setVisible(false); ch.setVisible(true); ch.setForeground(Color.red); ch.setBackground(Color.red); for (String font : Toolkit.getDefaultToolkit().getFontList()) { for (int j = 8; j < 17; j++) { Font f1 = new Font(font, Font.PLAIN, j); Font f2 = new Font(font, Font.BOLD, j); Font f3 = new Font(font, Font.ITALIC, j); Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j); ch.setFont(f1); ch.setFont(f2); ch.setFont(f3); ch.setFont(f4); ch.getFontMetrics(f1); ch.getFontMetrics(f2); ch.getFontMetrics(f3); ch.getFontMetrics(f4); } } ch.enable(); ch.disable(); ch.reshape(10, 10, 10, 10); ch.getBounds(new Rectangle(1, 1, 1, 1)); ch.getSize(new Dimension(1, 2)); ch.getLocation(new Point(1, 2)); ch.getX(); ch.getY(); ch.getWidth(); ch.getHeight(); ch.isOpaque(); ch.isValidateRoot(); ch.isOptimizedDrawingEnabled(); ch.isDoubleBuffered(); ch.getComponentCount(); ch.countComponents(); ch.getComponent(1); ch.getComponent(2); Component[] cs = ch.getComponents(); ch.getLayout(); ch.setLayout(new FlowLayout()); ch.doLayout(); ch.layout(); ch.invalidate(); ch.validate(); ch.remove(0); ch.remove(c2); ch.removeAll(); ch.preferredSize(); ch.minimumSize(); ch.getComponentAt(1, 2); ch.locate(1, 2); ch.getComponentAt(new Point(1, 2)); ch.isFocusCycleRoot(new Container()); ch.transferFocusBackward(); ch.setName("goober"); ch.getName(); ch.getParent(); ch.getGraphicsConfiguration(); ch.getTreeLock(); ch.getToolkit(); ch.isValid(); ch.isDisplayable(); ch.isVisible(); ch.isShowing(); ch.isEnabled(); ch.enable(false); ch.enable(true); ch.enableInputMethods(false); ch.enableInputMethods(true); ch.show(); ch.show(false); ch.show(true); ch.hide(); ch.getForeground(); ch.isForegroundSet(); ch.getBackground(); ch.isBackgroundSet(); ch.getFont(); ch.isFontSet(); Container c = new Container(); c.add(ch); ch.getLocale(); for (Locale locale : Locale.getAvailableLocales()) ch.setLocale(locale); ch.getColorModel(); ch.getLocation(); boolean exceptions = false; try { ch.getLocationOnScreen(); } catch (IllegalComponentStateException e) { exceptions = true; } if (!exceptions) throw new RuntimeException("IllegalComponentStateException did not occur when expected"); ch.location(); ch.setLocation(1, 2); ch.move(1, 2); ch.setLocation(new Point(1, 2)); ch.getSize(); ch.size(); ch.setSize(1, 32); ch.resize(1, 32); ch.setSize(new Dimension(1, 32)); ch.resize(new Dimension(1, 32)); ch.getBounds(); ch.bounds(); ch.setBounds(10, 10, 10, 10); ch.setBounds(new Rectangle(10, 10, 10, 10)); ch.isLightweight(); ch.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); ch.getCursor(); ch.isCursorSet(); ch.inside(1, 2); ch.contains(new Point(1, 2)); ch.isFocusable(); ch.setFocusable(true); ch.setFocusable(false); ch.transferFocus(); ch.getFocusCycleRootAncestor(); ch.nextFocus(); ch.transferFocusUpCycle(); ch.hasFocus(); ch.isFocusOwner(); ch.toString(); ch.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); ch.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); ch.setComponentOrientation(ComponentOrientation.UNKNOWN); ch.getComponentOrientation(); }
/** * Saves all configuration settings when the "Save" button is pressed. * * @param e the <tt>ActionEvent</tt> that notified us of the button action */ public void actionPerformed(ActionEvent e) { JButton button = (JButton) e.getSource(); if (button.equals(saveButton)) { Iterator<ChatRoomConfigurationFormField> configurationSet = configForm.getConfigurationSet(); while (configurationSet.hasNext()) { ChatRoomConfigurationFormField formField = configurationSet.next(); // If the field is of type fixed the user could not change it, // so we skip it. if (formField.getType().equals(ChatRoomConfigurationFormField.TYPE_TEXT_FIXED)) continue; JComponent c = uiFieldsTable.get(formField.getName()); if (c instanceof JTextComponent) { String newValue = ((JTextComponent) c).getText(); if (formField.getType().equals(ChatRoomConfigurationFormField.TYPE_ID_MULTI)) { // extract values StringTokenizer idTokens = new StringTokenizer(newValue, System.getProperty("line.separator")); while (idTokens.hasMoreTokens()) { formField.addValue(idTokens.nextToken()); } } else formField.addValue(newValue); } else if (c instanceof AbstractButton) { boolean isSelected = ((AbstractButton) c).isSelected(); formField.addValue(isSelected); } else if (c instanceof JComboBox) { Object selectedObject = ((JComboBox) c).getSelectedItem(); formField.addValue(selectedObject); } else if (c instanceof JPanel) { Component[] components = c.getComponents(); for (Component comp : components) { if (!(comp instanceof JCheckBox)) continue; JCheckBox checkBox = (JCheckBox) comp; formField.addValue(checkBox.getText()); } } } new Thread() { @Override public void run() { try { configForm.submit(); } catch (Exception e) { new ErrorDialog( ChatRoomConfigurationWindow.this, GuiActivator.getResources().getI18NString("service.gui.ERROR"), GuiActivator.getResources() .getI18NString("service.gui.CHAT_ROOM_CONFIGURATION_SUBMIT_FAILED"), e) .showDialog(); } } }.start(); } this.dispose(); }