From: Knute Johnson on
Andreas Leitgeb wrote:
> Knute Johnson <nospam(a)rabbitbrush.frazmtn.com> wrote:
>> I'm sorry, it's just not clear to me what you are trying to do. Maybe
>> an SSCCE would help?
>
> I don't see, how an SSCCE would help in this particular situation.
> SSCCE's are, if I see some behaviour that I don't want and cannot
> explain.
>
> In my case I *want* some particular behaviour, and if I could code
> that behaviour into an SSCCE, I wouldn't need to ask the question
> in the first place. Since I do not yet know how to code that
> behaviour, I'm still bound to describe it, and I can't see how
> anyone would understand my description better, just because they
> now have a window with a particular layout that behaves some
> other way.
>
> I'll try it now some other way. Giving names to things often
> helps, afterall.
>
> That's the layout:
> JSplitPane jsp1=new JSplitPane()
> JSplitPane jsp2=new JSplitPane()
> JSplitPane jsp3=new JSplitPane()
> jsp1.add(jsp2); jsp1.add(jsp3);
> jsp2.add(comp1); jsp2.add(comp2);
> jsp3.add(comp3); jsp3.add(comp4);
>
> Each of the components comp1-comp4 can be assumed to have
> reasonable (and in my case non-zero) minimum and preferred
> sizes.
>
> What I'm after in this thread is: if the user uses those
> little arrow-buttons in jsp3's splitter to minimize(hide) comp4,
> then (rather than comp3 alone growing for the freed space) I'd
> like all comp1,comp2 and comp3 to grow equally. For this, the
> jsp3 would have to inform jsp1 of a reduced preferred size
> (which of course isn't standard behaviour of splitpanes), and
> let jsp1 rearrange the space among it's child splitpanes, so
> in the end comp1, comp2 and comp3 are equal-sized and together
> consume the same screenspace as did comp1-comp4 before the user's
> action.
>
> Maybe I'm missing something obvious, but I don't see where
> and how I could add a callback to be informed of user clicking
> those minimize-buttons in the splitter.
>

OK, I think I understand what you want to do now. The only way I can
think to approach this is to use a ComponentListener and snag resize
events. Adjust the middle divider according to the percentage of window
covering the hidden component. It's a tricky one for sure.

--

Knute Johnson
email s/nospam/knute2009/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
From: Andreas Leitgeb on
Patricia Shanahan <pats(a)acm.org> wrote:
> You could write an SSCCE that exhibits the behavior you don't like, and
> explain what is wrong in terms of what that application does. That would
> give people a test case for experiments.

Ok, convinced me, and sorry for taking so long for it...

Notes:
- I'm really a newbie to Java *GUI* programming and haven't
yet found how to exit the app on Alt-F4. Therefore
the java-process needs to be killed separately afterwards.
(My actual program is an Applet, so I don't have the problem
there.) I guess it's just a question of adding some Listener
that calls some exit-method somewhere...
- What I want here is obviously pushing JSplitPane's envelope.
I quite likely will need some more own code in Listeners to
add at various places.

What I like/dislike in current behaviour:
- initially the last component is now hidden (good)
- but the third one takes double space instead (bad)
I'd like the space to be equally shared among the visible ones.
- if I enlarge the frame (or move the middle slider), it unminimizes
comp4 to its minimumSize (bad) (this doesn't happen if comp4
had been manually minimized, despite its non-zero minimumSize.)
How do I get comp4 initially minimized such that it doesn't re-
appear on resizes from the outside?
- If instead comp4 is initially unminimized, and then the middle
slider is moved (a little), the other sliders stay where they
are (a result of the rather strange resizeWeights) (good)
Otoh, it impedes proper equal resizing of the components (bad),
so it is just a limited quality workaround.
- I can move the middle slider further and push away the other ones,
but with the other ones, I cannot push the middle slider. This
is logical behaviour from implementation POV, but unlogical for
the user. (bad)
- Creating a 4-pane consistent MegaSplitPane from normal SplitPanes
likely isn't a trivial thing, but perhaps some aspects are easier
to fix than by a full rewrite of SplitPane and its plaf.

Finally, here is the code:
for easy retrieval from www:
http://www.logic.at/people/avl/stuff/LayoutDemo.java

and inline for easier discussion:
(please don't comment on style - it's an SSCCE, not a model)
-----snip to end----
import java.awt.Dimension;
import javax.swing.*;

public class LayoutDemo extends JFrame {
private JSplitPane[] jsps=new JSplitPane[3];
private JButton[] jbs=new JButton[4];

public LayoutDemo() {
for (int i=0;i<4;i++) {
JButton jb=jbs[i]=new JButton("comp"+(i+1));
jb.setMinimumSize(new Dimension(50,50));
jb.setPreferredSize(new Dimension(150,150));
}

// this one is nice for moving the middle slider:
final double rw[]= { 0.0, 0.5, 1.0 };

for (int i=0;i<3;i++) {
JSplitPane jsp=jsps[i]=new JSplitPane();
jsp.setOneTouchExpandable(true);
jsp.setResizeWeight( rw[i] );
jsp.setContinuousLayout( true );
}

jsps[0].setLeftComponent(jbs[0]);
jsps[0].setRightComponent(jbs[1]);
jsps[1].setLeftComponent(jsps[0]);
jsps[1].setRightComponent(jsps[2]);
jsps[2].setLeftComponent(jbs[2]);
jsps[2].setRightComponent(jbs[3]);

jsps[2].setDividerLocation(10000);
jsps[2].setLastDividerLocation(-1);

getContentPane().add(jsps[1], java.awt.BorderLayout.CENTER);
pack();

setSize(700,200);
setVisible(true);
}

public static void main(String args[]) {
new LayoutDemo();
}
}
From: John B. Matthews on
In article <slrnhbaf0h.5sv.avl(a)gamma.logic.tuwien.ac.at>,
Andreas Leitgeb <avl(a)gamma.logic.tuwien.ac.at> wrote:

[...]
> - I'm really a newbie to Java *GUI* programming and haven't
> yet found how to exit the app on Alt-F4. Therefore
> the java-process needs to be killed separately afterwards.
> (My actual program is an Applet, so I don't have the problem
> there.) I guess it's just a question of adding some Listener
> that calls some exit-method somewhere...

I'm not sure about Alt-F4, but you can set the JFrame's default close
operation in the constructor:

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

[...]

> - if I enlarge the frame (or move the middle slider), it unminimizes
> comp4 to its minimumSize (bad) (this doesn't happen if comp4
> had been manually minimized, despite its non-zero minimumSize.)
> How do I get comp4 initially minimized such that it doesn't re-
> appear on resizes from the outside?

Give the last component a preferred size of zero:

jbs[3].setMinimumSize(new Dimension(0,0));

Sorry, I'm not sure about the other stuff.

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
From: Andreas Leitgeb on
John B. Matthews <nospam(a)nospam.invalid> wrote:
> I'm not sure about Alt-F4, but you can set the JFrame's default close
> operation in the constructor:
> setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Thanks! Yes, that works also for Alt-F4. Surely for any keycombo
that one's WM has bound to closing a window. In hindsight it seems
so obvious, that I grumble at myself for not having had a look at
javadoc for JFrame, but only for JSplitPane ...

>> - if I enlarge the frame (or move the middle slider), it unminimizes
>> comp4 to its minimumSize (bad) (this doesn't happen if comp4
>> had been manually minimized, despite its non-zero minimumSize.)
> Give the last component a preferred size of zero:
> jbs[3].setMinimumSize(new Dimension(0,0));

That's of course the obvious "workaround", but the problem is, that setting
the dividerLocation to a large value just is not the same as the effect of
user pressing the maximize button. If I set the minimumSize to 0,0 then
the difference still shows up somewhere else - like when the splitpane
itself is resized and had a resizeWeight < 1.0, then upon enlargening
the splitpane the supposedly minimized window would still reappear.
In the example, set minimumSize to 0,0 and the rw[] to {0.5,0.5,0.5}
then recompile/run and move the middle slider to the left a bit.

I appreciate your intention to help on this one.

From: Andreas Leitgeb on
RedGrittyBrick <RedGrittyBrick(a)SpamWeary.invalid> wrote:
> Maybe this will help?
> http://www.java2s.com/Tutorial/Java/0240__Swing/DistributingSpaceWhenaJSplitPaneContainerIsResized.htm

That covers the standard features of JSplitPane, which my demands seem
to leave far behind.
Even the nested example is one, where the inner splitpane has a different
orientation from the outer one, and the problems I have with nesting
equally-oriented splitpanes do not show up there.

Thanks anyway for trying to help.

PS: Meanwhile I've posted an SSCCE.
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: Adding int to a float
Next: how to enlarger Java heap size?