protected void setBackgroundColor(Color color) { super.setBackgroundColor(color); if (m_cmbUser != null) ((BasicComboBoxRenderer) m_cmbUser.getRenderer()).setBackground(color); }
public CustomDialog(Frame name) { super(name, "Customize Text Properties", true); this.setResizable(false); this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fontList = ge.getAvailableFontFamilyNames(); fontCombo = new JComboBox(fontList); italic = new JCheckBox("Italic"); bold = new JCheckBox("Bold"); sizeCombo = new JComboBox(stringSize); ((JLabel) sizeCombo.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER); sizeCombo.setSelectedIndex(4); sizeCombo.setPreferredSize(new Dimension(45, 21)); // tweek size example = new JTextField(" Preview "); example.setHorizontalAlignment(SwingConstants.CENTER); example.setFont(new Font("sanserif", Font.PLAIN, 28)); example.setEditable(false); ok = new JButton("Apply"); cancel = new JButton("Cancel"); ok.setPreferredSize(cancel.getPreferredSize()); foreground = new JButton("Edit Color"); foreground.setPreferredSize(new Dimension(100, 50)); // add the listeners fontCombo.addActionListener(this); italic.addItemListener(this); bold.addItemListener(this); sizeCombo.addActionListener(this); ok.addActionListener(this); cancel.addActionListener(this); foreground.addActionListener(this); JPanel p0 = new JPanel(); p0.add(fontCombo); p0.setBorder(new TitledBorder(new EtchedBorder(), "Font family")); JPanel p1a = new JPanel(); p1a.add(italic); p1a.add(bold); p1a.setBorder(new TitledBorder(new EtchedBorder(), "Font style")); JPanel p1b = new JPanel(); p1b.add(sizeCombo); p1b.add(new JLabel("pt.")); p1b.setBorder(new TitledBorder(new EtchedBorder(), "Font size")); JPanel p1 = new JPanel(); p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS)); p1.add(p1a); p1.add(p1b); p1.setAlignmentX(Component.CENTER_ALIGNMENT); JPanel p2 = new JPanel(); // use FlowLayout p2.add(foreground); p2.setBorder(new TitledBorder(new EtchedBorder(), "Message color")); p2.setAlignmentX(Component.CENTER_ALIGNMENT); JPanel p3 = new JPanel(); p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS)); p3.add(example); p3.setPreferredSize(new Dimension(250, 60)); p3.setMaximumSize(new Dimension(250, 60)); p3.setAlignmentX(Component.CENTER_ALIGNMENT); JPanel p4 = new JPanel(); p4.add(ok); p4.add(cancel); p4.setAlignmentX(Component.CENTER_ALIGNMENT); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); p.add(p0); p.add(Box.createRigidArea(new Dimension(0, 10))); p.add(p1); p.add(Box.createRigidArea(new Dimension(0, 10))); p.add(p2); p.add(Box.createRigidArea(new Dimension(0, 10))); p.add(p3); p.add(Box.createRigidArea(new Dimension(0, 10))); p.add(p4); p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); Dimension d1 = p3.getPreferredSize(); Dimension d2 = p1.getPreferredSize(); p1.setPreferredSize(new Dimension(d1.width, d2.height)); p1.setMaximumSize(new Dimension(d1.width, d2.height)); d2 = p2.getPreferredSize(); p2.setPreferredSize(new Dimension(d1.width, d2.height)); p2.setMaximumSize(new Dimension(d1.width, d2.height)); this.setContentPane(p); this.pack(); }