簡體   English   中英

JFrame調整大小

[英]JFrame Resizing

我切換到MigLayout,當我將窗口拖動到較小的位置時,組件的大小會調整,但是當我將其拖動到大於啟動程序時的大小時,它們不會變大。 我如何使它變大和變小?

public SpriteEditor() {
    SubstanceColorChooserUI col = new SubstanceColorChooserUI();
    while (mode == 0);
    setResizable(true);
    setTitle("DawnGuard Index 32/34 Editor");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setSize(483, 374);
    setLocationRelativeTo(null);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);

    textField = new JTextField();
    textField.setColumns(10);

    JButton btnLoadCache = new JButton("Load cache");
    btnLoadCache.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
                String loc = textField.getText();
                if (loc.equals("")) {
                    JOptionPane.showMessageDialog(SpriteEditor.this, "Please specify a location for the cache.", "Unable to load", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if (!loc.endsWith("\\"))
                    loc = loc + "\\";
                cache = new Store(loc);
                loadImages();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(SpriteEditor.this, "Cache failed to initialize.\n" + e.getMessage(), "Unable to load", JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    JSplitPane splitPane = new JSplitPane();
    splitPane.setDividerLocation(150);
    splitPane.setContinuousLayout(true);

    JPanel panellie = new JPanel();
    panellie.setLayout(new BorderLayout(0, 0));
    panel = new ImagePanel(null);

    scrollPane_1 = new JScrollPane();
    panellie.add(scrollPane_1, "Center");

    scrollPane_1.setViewportView(panel);
    splitPane.setRightComponent(panellie);

    JPanel panel_1 = new JPanel();
    splitPane.setLeftComponent(panel_1);
    panel_1.setLayout(new BorderLayout(0, 0));

    JScrollPane scrollPane = new JScrollPane();
    panel_1.add(scrollPane, BorderLayout.CENTER);

    model = new DefaultListModel<ListedImage>();
    list = new JList<ListedImage>(model);
    list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent arg0) {
            if (arg0.getValueIsAdjusting())
                return;
            ListedImage img = list.getModel().getElementAt(list.getSelectedIndex());
            panel.setImage(img.getImage());
        }
    });
    scrollPane.setViewportView(list);

    progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    progressBar.setDoubleBuffered(true);

    contentPane.setLayout(new MigLayout("", "[328px][13px][112px]", "[23px][279px][14px]"));
    contentPane.add(textField, "cell 0 0,growx,aligny center");
    contentPane.add(btnLoadCache, "cell 2 0,growx,aligny top");
    contentPane.add(splitPane, "cell 0 1 3 1,grow");
    contentPane.add(progressBar, "cell 0 2 3 1,grow");

}

在布局定義中,您可以:

contentPane.setLayout(new MigLayout("", "[328px][13px][112px]", "[23px][279px][14px]"));

好吧,您可以嘗試告訴布局以布局約束fill ,現在您應該告訴當面板隨着行/列約束的grow增長時,夾層的列和行應該grow 所以...

contentPane.setLayout(new MigLayout("fill", "[328px, grow][13px][112px]", "[23px][279px, grow][14px]"));

我猜最大尺寸太小,您試圖將尺寸設置為大於對象的最大尺寸。 嘗試設置最大寬度和最大高度。 祝好運。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM