Example #1
0
  private MainPanel() {
    super(new GridLayout(3, 1, 5, 5));
    final JTree tree = new JTree();
    final JCheckBox c = new JCheckBox("CheckBox", true);
    c.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            tree.setEnabled(c.isSelected());
          }
        });
    c.setFocusPainted(false);
    JScrollPane l1 = new JScrollPane(tree);
    l1.setBorder(new ComponentTitledBorder(c, l1, BorderFactory.createEtchedBorder()));

    JLabel icon = new JLabel(new ImageIcon(getClass().getResource("16x16.png")));
    JLabel l2 = new JLabel("<html>aaaaaaaaaaaaaaaa<br>bbbbbbbbbbbbbbbbb");
    l2.setBorder(new ComponentTitledBorder(icon, l2, BorderFactory.createEtchedBorder()));

    JButton b = new JButton("Button");
    b.setFocusPainted(false);
    JLabel l3 = new JLabel("ccccccccccccccc");
    l3.setBorder(new ComponentTitledBorder(b, l3, BorderFactory.createEtchedBorder()));

    add(l1);
    add(l2);
    add(l3);
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setPreferredSize(new Dimension(320, 240));
  }
Example #2
0
 public Component getListCellRendererComponent(
     JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
   JCheckBox checkbox = (JCheckBox) value;
   if (!UIUtil.isUnderNimbusLookAndFeel()) {
     checkbox.setBackground(getBackground(isSelected, checkbox));
     checkbox.setForeground(getForeground(isSelected, checkbox));
   }
   checkbox.setEnabled(isEnabled());
   checkbox.setFont(getFont(checkbox));
   checkbox.setFocusPainted(false);
   checkbox.setBorderPainted(true);
   checkbox.setBorder(isSelected ? mySelectedBorder : myBorder);
   adjustRendering(checkbox, isSelected, cellHasFocus);
   return checkbox;
 }
 public Component getListCellRendererComponent(
     JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
   if (containerBox == null) {
     containerBox = Box.createHorizontalBox();
     checkBox = new JCheckBox();
     checkBox.setEnabled(isEnabled());
     checkBox.setFont(getFont());
     checkBox.setFocusPainted(false);
     checkBox.setBorderPainted(true);
     checkBox.setBorder(
         isSelected ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder);
     containerBox.add(checkBox);
   }
   checkBox.setBackground(isSelected ? getSelectionBackground() : getBackground());
   checkBox.setForeground(isSelected ? getSelectionForeground() : getForeground());
   if (value != null) {
     ListItem item = (ListItem) value;
     checkBox.setText(item.dataItem.toString());
     checkBox.setSelected(item.selected);
   }
   return containerBox;
 }