2

I'm using JXMultiSplitPane (from SwingX 1.6.2) to implement a three-pane horizontal interface. In the center pane is a JTabbedPane with two tabs: one with a JTextArea (in a JScrollPane, of course) used for entering Markdown code and the other a JEditorPane (again, in a scroll pane) for displaying a rendered HTML preview. When the user switches to the preview pane, the text in the editor is processed and displayed in the preview pane.

My problem is that if I enter text in the editor with long lines, and then switch to the preview, the center pane will expand. Sometimes it's just by a little bit, other times it'll take up more room than is actually on the screen. But if I move one of the resize handles manually, everything will snap back in place.

I've found only two ways to deal with this before it happens:

  1. Manually resize one of the panes before entering any text.
  2. Give the center pane a weight of 1 in the MultiSplitLayout model.

I can't use the second one since it will expand the center pane to take up almost the whole window by default.

Is there a way to fix this?

Update

After a little more testing, even technique (2) doesn't keep the size constant; switching between the two tabs changes the size of the center pane slightly.

I now believe that the problem is partly with the tabbed pane. The JTextArea and the JEditorPane do not have the same size and that JTabbedPane is resizing when I switch between them (since I'm resetting the JEditorPane text every time. This wouldn't be a problem except that JXMultiSplitPane will keep automatically resizing the center pane until the user forces a specific size by resizing manually.

So I should be able to fix the issue by making the size of the JTabbedPane fixed, but still able to be resized by the handle bars. Any tips on doing that?

kleopatra
  • 51,061
  • 28
  • 99
  • 211
James Jensen
  • 363
  • 3
  • 8
  • hmm... might as well be a bug or missing feature in the splitpane. Please consider to file an issue in the swingx issue-tracker, you can simply link to this description (though a short runnable example would be great :-) – kleopatra Aug 21 '11 at 08:55

1 Answers1

1

The MultiSplitLayout is .. a LayoutManager, so you have to understand how it works (me too, not overly familiar with it myself :-)

The basic layout happens according to the component's prefSize, the weights are for distributing excess/missing space relative to the pref. By default, the dividers are "floating", that is they are positioned between the components as layouted by the basic mechanism. The moment a user touches a divider, dividers are "not-floating", comp sized to fit in-between the dividers. That's the reason for you not seeing the size-greed after moving the divider once. So one ways out is to

  • setup the JXMultiSplitPane as usual, add the components and realize the frame
  • fix the dividers after the manager has done its initial layout

    String layout = "(ROW " +
        "(LEAF name=selector weight=0.15)" +
        "(LEAF name=center weight=0.7)" +
        "(LEAF name=list weight=0.15)" +
    ")";
    
    JXMultiSpitPane pane = new JXMulitSplitPane((MultiSplitLayout.parseModel(layout))
    // add components and realize the frame  
    ...
    pane.getMultiSplitLayout().setFloatingDividers(false);
    

Alternatively, give more weight to the weights - force the layoutManager to use them for the layout itself (instead of only for the distribution of excess/missing space). A side-effect is that the prefSize of the comps might be set (by the layout, which is a no-no-never, but who's perfect ;-)

   pane.getMulitSplitLayout().setLayoutByWeights(true);

Not sure which way I would prefer or if/how that could be made easier in the multisplit ..

kleopatra
  • 51,061
  • 28
  • 99
  • 211