so i have a problem i cant solve i want my GUI app to be split between 3 JPanels (left, center, right). I want left panel and right panel to be of fixed size and center to be fluid. Meaning side panels expand only vertically as JFrame is expanded and center panel expands bot horizontally and vertically.
I have set minimal size for all panels to be height of 600 but they just stay in the minimal size and dont expand as JForm increases i dont know how to set bounds to JFrame borders so they expand whit it.
package ppe.view;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import net.miginfocom.swing.MigLayout;
public class UI_View extends JFrame
{
private JList browse = new JList();
private JScrollPane rightX = new JScrollPane();
private JButton btn1 = new JButton("Button 1");
private JButton btn2 = new JButton("Button 2");
private JButton btn3 = new JButton("Button 3");
private JButton btn4 = new JButton("Button 4");
public UI_View()
{
this.setTitle("Prototype MVC Arhitecture");
this.setMinimumSize(new Dimension(800, 600));
this.setExtendedState(this.MAXIMIZED_BOTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new MigLayout());
JPanel content = new JPanel(new MigLayout());
content.setBackground(Color.black);
JPanel right = new JPanel(new MigLayout());
JPanel center = new JPanel(new MigLayout());
JPanel left = new JPanel(new MigLayout());
right.setBackground(Color.red);
right.setMinimumSize(new Dimension(200, 600));
right.setMaximumSize(new Dimension(200, 37500));
center.setBackground(Color.green);
center.setMinimumSize(new Dimension(400, 600));
left.setBackground(Color.blue);
left.setMinimumSize(new Dimension(200, 600));
left.setMaximumSize(new Dimension(200, 37500));
content.add(left);
content.add(center);
content.add(right);
this.setContentPane(content);
}
public static void main(String[] args)
{
new UI_View().setVisible(true);
}
}
I have tryed bounding them to another content panel and adding that panel as ContentPane to JFrame that automatically bounds it to JFrame border but the thing is still pretty much fixed.
If you’re using
MiGLayoutwhy don’t you configure the constraints when adding the components?This, for example, might help (although I’m a
MiGLayoutbeginner, too):In some cases I needed to also add a
pushxbut I’m not sure when this is needed. Please refer to the documentation for further information.Edit: it seems like you always have to add
pushfor components that should cause the column/row to grow. Otherwisegrowalone would make the components as big as the column/row they are in which in turn is defined by the largest component in that column/row. If there is more space available columns/rows won’t grow to fill it without thepushkeyword.From the documentation: