Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4515838

Can't change the border of a JComboBox

XMLWordPrintable

      Name: gm110360 Date: 10/17/2001


      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      I add a JComboBox in a toolbar (inside a JFrame), and I'dlike to remove the border of the JComboBox. I can remove the border of the JButton of the toolbar, but I can't change the border of the JComboBox.
      Setting a new border in it just adds the border to the default border of the JComboBox, but does not replace it.

      This is a piece of code which reproduce the problem :

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class JComboProblem extends JFrame
      {

      public JComboProblem()
      {
      super();

      addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent ev) {
      System.exit(0);
      }
      });

      JPanel panel = new JPanel(new BorderLayout());
      getContentPane().add(panel);

      JToolBar tb = new JToolBar();
      panel.add(tb, BorderLayout.NORTH);

      JButton button = new JButton("Do nothing");
      button.setBorderPainted(false);
      tb.add(button);

      JComboBox cb = new JComboBox();

      cb.addItem("25%");
      cb.addItem("50%");
      cb.addItem("100%");
      cb.addItem("200%");

      cb.setMaximumSize(cb.getMinimumSize());
      tb.add(cb);

      // cb.setBorder(null); // Do nothing
      cb.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); // Do nothing
      // cb.setBorder(BorderFactory.createEtchedBorder()); // Adds the border to the existing border but does not replace it

      setSize(400, 300);
      setVisible(true);
      }

      public static void main(String argv[])
      {
      new JComboProblem();
      }
      }

      I could be useful to have a JComboBox.setBorderPainted (and JComboBox.setFocusPainted) method(s).
      (Review ID: 133889)
      ======================================================================

            alexp Alexander Potochkin (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: