Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

java - Grow table larger than growx

I have configured my layout like that:

    panel.add(addButtons(), "wrap");    
    panel.add(showTable(), "growx, wrap");

So at first I am adding a button group and then I would like to grow my table as large as it can and then wrap the next component in the next "line".

However, my gui looks like that:

enter image description here

Here you clearly cannot see any values from the table. Therefore, how to grow the table so that each value can be seen?

I appreciate your answer!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here you clearly cannot see any values from the table. Therefore, how to grow the table so that each value can be seen?

As I've said in my comment, I don't think your problem is about columns (preferred | min | max) sizes but the default behavior of your layout manager: MigLayout. As stated in this answer by default rows in MigLayout doesn't fill all available width but just the necessary to display the longest row (based on components width). You can see this fact if you enable "debug" feature when you instantiate your layout:

MigLayout layout = new MigLayout("debug");

As I understand your question you need a combination of both growx and fillx constraint. The first one is a component constraint and the other one is a layout constraint.

That being said, pelase consider the following progression.

1. Adding scroll pane without "growx" constraint

Snippet

MigLayout layout = new MigLayout("debug");
JPanel panel = new JPanel(layout);
panel.add(buttonsPanel, "wrap");
panel.add(scrollPane);

Screenshot

Without growx constraint

2. Adding scroll pane with "growx" constraint

Snippet

MigLayout layout = new MigLayout("debug");
JPanel panel = new JPanel(layout);
panel.add(buttonsPanel, "wrap");
panel.add(scrollPane, "growx"); // Note "growx" here

Screenshot

With growx constraint

3. Adding scroll pane with "growx" and "fillx" contraints

Snippet

MigLayout layout = new MigLayout("debug, fillx"); // Note "fillx" here
JPanel panel = new JPanel(layout);
panel.add(buttonsPanel, "wrap");
panel.add(scrollPane, "growx"); // Note "growx" here

Screenshot

With growx and fillx constraints


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...