2012-07-19 109 views
2

我切换到MigLayout,当我拖动窗口变小时,组件调整大小,但是当我将其拖动大于启动程序时的大小时,它们不会变大。我如何使它变得越来越小?JFrame调整大小

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"); 

} 
+0

我自己,我建议不要试图手动编码GroupLayout。使用使用更简单的布局管理器的嵌套JPanel或下载MigLayout并使用它们更好。 – 2012-07-19 21:54:50

+0

我使用windowbuilder进行日食 – 2012-07-19 21:55:30

+0

编辑:我只是使用MigLayout,但它不能调整更大,只能更小。 – 2012-07-19 21:56:22

回答

1

在布局定义你:

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

好,你可以试着告诉布局,以填补布局约束fill,现在你应该告诉至极列(S)和行(S)要长时面板随着行/列约束grow增长。所以...

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

我猜最大尺寸太小,你试图设置一个比对象的最大尺寸更大的尺寸。尝试设置最大宽度和最大高度。祝你好运。

+0

我该怎么做? – 2012-07-19 22:00:57

+0

只需调用JFrame对象的setMaximumSize方法即可。您应该传递一个Dimension对象,如下所示:myFrame.setMinimumSize(new Dimension(800,550)); myFrame是您的JFrame对象。 – 2012-07-19 22:06:45

+0

我更新了这篇文章,也没有工作。 – 2012-07-19 22:08:06

相关问题