Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 377922 - Swing: Wrong display of configured splitter position in split box
Summary: Swing: Wrong display of configured splitter position in split box
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Scout (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-27 10:42 EDT by Beat Schwarzentrub CLA
Modified: 2021-08-19 11:17 EDT (History)
5 users (show)

See Also:
judith.gull: juno+
judith.gull: luna+


Attachments
Proposed patch (1.35 KB, patch)
2012-04-27 10:43 EDT, Beat Schwarzentrub CLA
no flags Details | Diff
A test form that illustrates the problem (and fix) (1.80 KB, application/octet-stream)
2012-04-27 10:44 EDT, Beat Schwarzentrub CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Beat Schwarzentrub CLA 2012-04-27 10:42:56 EDT
Build Identifier: 

PROBLEM DESCRIPTION:
When using an AbstractSplitBox, the initial splitter position (getConfiguredSplitterPosition()) can be given as a percentage (e.g. 0.1 = first part takes 10% of the available space, second part takes 90%). However, the given value is often not displayed correctly, particularly for small or large values.

EVALUATION:
When the configured splitter position is sent from the Scout model to the Swing component (method javax.swing.JSplitPane.setDividerLocation(double)), the Swing component is not yet ready, so it does not have a height. Javadoc of the setDividerLocation() states clearly, that this situation leads to wrong results.

PROBOSED SOLUTION:
I will attach a patch that postpones the Swing calls by using SwingUtilities.invokeLater(). This seems to do the trick, but I'm not quite sure if this is _really_ the best possible fix. (Btw, I took the oportunity to change >0.0 and <1.0 to >=0.0 and <=1.0 to allow initial splitter positions that are at 0% or 100%.)

Reproducible: Always
Comment 1 Beat Schwarzentrub CLA 2012-04-27 10:43:25 EDT
Created attachment 214705 [details]
Proposed patch
Comment 2 Beat Schwarzentrub CLA 2012-04-27 10:44:21 EDT
Created attachment 214706 [details]
A test form that illustrates the problem (and fix)
Comment 3 Claudio Guglielmo CLA 2012-05-23 04:56:35 EDT
Hi Beat

As I was trying to reproduce the bug I noticed that setting the splitter position works fine with a value >= 0.17. With smaller values the position was wrong. 
Your patch seems to fix that but I'm not sure if it's the right way. Since it delays the setting of the splitter position it could lead to a flickering when opening the form which does not look nice. Unfortunately I don't have any better solution at the moment.
Comment 4 Stephan Merkli CLA 2013-09-16 02:23:21 EDT
Fix required for Scout 3.8 as well.
Comment 5 Jeremie Bresson CLA 2013-09-23 13:11:08 EDT
Change open for develop on Gerrit:
https://git.eclipse.org/r/16702

@Beat:
I could not use your patch (did not fix the problem), but thanks for the analysis and the example form. My solution works with a listener on the JSplitPane.

@Claudio:
Thanks for the analysis. The threshold value from 0.17 comes from:

(int)((double)(getHeight() - getDividerSize()) * proportionalLocation)

in javax.swing.JSplitPane.setDividerLocation(double)

because we have called this method too early, height was 0 and dividerSize was 6.
-6*0.17 < -1 
meaning that a value != 0 will be set.

With smaller value than 0.17, the cast as integer produce a value that is 0.
Comment 6 Jeremie Bresson CLA 2013-09-27 05:49:27 EDT
Merged for Luna M2 on develop:
http://git.eclipse.org/c/scout/org.eclipse.scout.rt.git/commit/?id=e80638cb512110f5c2445e70a03b327c881bf27a


(In reply to Stephan Merkli from comment #4)
> Fix required for Scout 3.8 as well.

@Ken:
Can you do the backport for Eclipse 3.8 ?
Comment 7 Ken Lee CLA 2013-09-27 09:10:14 EDT
> @Ken:
> Can you do the backport for Eclipse 3.8 ?

Patch backported to Scout 3.8.3 with Revision 3537.

@Stephan Merkli: Please verify the changes for Scout 3.8.3 and also for Scout 3.10.0-M2 with you don't mind ;-)
Comment 8 Stephan Merkli CLA 2013-09-30 01:49:24 EDT
Thank you for the fix.

Tested with Scout 3.8 and Scout 3.10
Comment 9 Matthias Zimmermann CLA 2014-07-01 03:19:27 EDT
Shipped with Eclipse Luna Release