Question

I am attempting to put a JGoodies panel into a JScrollPane with only a vertical scroll bar; any elements larger than the current JScrollPane width should be truncated. However I can't figure out a way to make this work

Example of the effect I'm going for Good example

What I don't want to happen bad example

My current code is essentially:

    FormLayout locationsLayout = new FormLayout("15dlu, pref, 5dlu, pref, 5dlu, pref:grow", "");
    locationsBuilder = new DefaultFormBuilder(locationsLayout)
            .background(Color.WHITE)
            .lineGapSize(Sizes.ZERO);
    locationsPane = new JScrollPane(locationsBuilder.getPanel());
    locationsPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    locationsPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

    //...Sometime later, the user adds a folder...
    FormLayout headerLayout = new FormLayout("pref, pref", "pref");
    DefaultFormBuilder headerBuilder = new DefaultFormBuilder(headerLayout)
            .background(Color.WHITE)
            .lineGapSize(Sizes.ZERO);
    headerBuilder.add(curContainer.getGuiHeader(), CC.xy(1, 1));
    headerBuilder.add(curContainer.getGuiTablePrefix(), CC.xy(2, 1));
    locationsBuilder.leadingColumnOffset(0);
    locationsBuilder.append(headerBuilder.getPanel(), 6);

Things I've tried

  • Various permutations of min, pref, grow, fill, etc. Nothing changed this behavior
  • Passing a custom JPanel that implements Scrollable to the locationsBuilder DefaultFormBuilder constructor as documented here, here, or here
  • Trying the other vertical scroll bar options on JScrollPane

I don't know what else I can try. Does anybody have any suggestions?

Was it helpful?

Solution

I never could find an exact answer to this specific setup. My guess is that JGoodies dies bit handle nested layouts very well.

I ended up "fixing" this by using only one single panel for the entire locations scroll pane. This made the layout a bit complicated: Multiple cells now had to span columns and I had to manually adjust the column offset. But in the end it works

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top