Java – width of jcombobox

I've created one jCombo@R_231_2419 @, but it requires the full width of the frame How to set a fixed width

For the frame and box layout of the panel, it is borderlayout I add code here:

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

public class Window8  {

    JFrame frame;
    JPanel panel;
    JCombo@R_231_2419@ combo;
    public void go(){

    String[] option = { "STUDENT","TEACHER" };

    combo.setPreferredSize(new Dimension(1,25));
    combo = new JCombo@R_231_2419@(option);
    menu.setSelectedIndex(0);

    frame = new JFrame("DELETION"); 
    frame.setLocationRelativeTo(null);
    frame.setSize(400,300);
    frame.setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

    panel = new JPanel();
    panel.setLayout(new @R_231_2419@Layout(panel,@R_231_2419@Layout.Y_AXIS));

    frame.getContentPane().add(BorderLayout.NORTH,panel);
    panel.add(combo);   
}

Solution

The width is automatically determined by the width of the largest item added to the combo box You can control the display in the following ways:

combo@R_231_2419@.setPrototypeDisplayValue("text here");

You can also consider using combo box popup to control the pop-up window size

Edit:

Because you have added a display that you are using @ R_ 231_ 2419@Layout Code, you can try the following:

combo@R_231_2419@.setMaximumSize( combo@R_231_2419@.getPreferredSize() );

Or you can do this:

JPanel wrapper = new JPanel();
wrapper.add( combo@R_231_2419@ );
panel.add( wrapper );

Read the swing tutorial section of using layout managers to learn how these suggestions work

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>