Probably the best and most modern layout for Java AWT/Swing
MIT License
Probably the best and most modern layout for Java AWT/Swing (Java 8 or higher required)
// ... window code not shown
BLayout rootLayout = new BLayout();
this.setContentPane(rootLayout);
rootLayout.isDebug = true;
rootLayout.access(() -> { // No need to call revalidate on any component inside here
BLayout lyTitle = new BLayout(rootLayout, true); // true = crop to content
rootLayout.addV(lyTitle);
JLabel title = new JLabel(), subtitle = new JLabel();
title.setText("My title");
title.putClientProperty("FlatLaf.style", "font: 200% $semibold.font");
lyTitle.addH(titleAutoPlug).paddingLeft();
subtitle.setText("| my subtile");
subtitle.putClientProperty("FlatLaf.style", "font: 200% $light.font");
lyTitle.addH(titleTray).paddingLeft();
rootLayout.addV(new JLabel("VERTICAL")); // Basically the same as "\n" in a string.
rootLayout.addH(new JLabel("HORIZONTAL"), new JLabel("HORIZONTAL"), new JLabel("HORIZONTAL"));
rootLayout.addV(new JLabel("VERTICAL"));
rootLayout.addH(new JLabel("HORIZONTAL"));
new BLayout(rootLayout, 30, 10) // 30% width and 10% height
.addV(new JLabel("Lorem ipsum dolor sit amet! "),
new JLabel("Lorem ipsum dolor sit amet! "),
new JLabel("Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet"),
new JLabel("Lorem ipsum dolor sit amet! "),
new JLabel("Lorem ipsum dolor sit amet! "))
.makeScrollable(); // This adds the scroll layout to the rootLayout
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab("hello!", new BLayout()); // 100% of window
rootLayout.addV(tabbedPane);
});
access()
method.addV()
and addH()
methods.