#[Java related] Java Swing
1 messages · Page 1 of 1 (latest)
I recommend working with GradBagLayout
not using it is a bit like shooting yourself in the food
I've worked out why and i dont really udnerstand GridBagLayout
I'll give it another go I guess
JPanel extensionList = (JPanel) getTopComponent();
GridBagLayout layout = new GridBagLayout();
extensionList.setLayout(layout);
// <...>
JLabel latestVersion = new JLabel(desc.latestVersion);
MouseClickListener listener = new MouseClickListener(new ExtensionSelector(parent, row - 1, this));
latestVersion.addMouseListener(listener);
if (latestVersion.getPreferredSize().width > versionWidth) {
versionWidth = latestVersion.getPreferredSize().width;
layout.columnWidths = new int[] {nameWidth, descriptionWidth, versionWidth};
}
GridBagConstraints versionConstraint = new GridBagConstraints();
versionConstraint.gridx = 2;
versionConstraint.gridy = row;
versionConstraint.ipady = 5;
versionConstraint.anchor = GridBagConstraints.WEST;
versionConstraint.fill = GridBagConstraints.HORIZONTAL;
extensionList.add(latestVersion, versionConstraint);
is an example of how I use it in one of my older projects.
It's rather easy tbh - but I didn't understand it at first either