JComboBox width

后端 未结 5 964
南旧
南旧 2020-12-15 08:31

I have created a jComboBox but it takes the full width of the frame. how to set the width fixed.

yes borderlayout for the frame and box layout for the panel. i am

5条回答
  •  温柔的废话
    2020-12-15 08:58

    Here is something you can do with box layout.

    • Change axis to line axis, Add
    • horizontal glue, Add rigid area,
    • place the component

    . code snippet below:

    panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
    panel.add(Box.createHorizontalGlue());
    panel.add(Box.createRigidArea(new Dimension(10, 0)));
    panel.add(combo);
    frame.getContentPane().add(BorderLayout.NORTH, panel);
    

提交回复
热议问题