<Swing Dev> JSplitPane / heavyweight vs. lightweight components

Anthony Petrov anthony.petrov at oracle.com
Tue Jan 17 13:48:24 UTC 2012


Hi Johannes,

Does running your app with the -Djava.awt.smartInvalidate=true command 
line argument resolve anything? Please note that you have to execute 
this workaround revalidation mantra upon any changes performed by the 
user to the JSplitPane (i.e. on each moving of the split pane divider). 
Also, when running with the smartInvalidate=true, you don't need to call 
window.validate().

As to a simple test, please try to create a frame, put a split pane into 
it, and add a heavyweight AWT java.awt.Panel into it instead of a 
PApplet instance. This should work pretty much the same as your real 
app. If you can reproduce the problem with such a simple test, please 
post its source to the mailing list.

--
best regards,
Anthony

On 1/16/2012 8:42 PM, Johannes.Lichtenberger wrote:
> Hello,
> 
> I'm adding a JSplitPane to a JPanel within a frame, and the frame has a
> JMenuBar added. I'm now adding a JPanel component which embeds a PApplet
> component (processing from processing.org) which extends Applet to the
> JSplitPane. It doesn't seem to work even though I've added
> 
>     /**
>      * Handle mix of heavyweight ({@link PApplet}) and leightweight (
> {@link JMenuBar}) components.
>      */
>     public void handleHLWeight() {
>         final Container parent = mView.component().getParent();
>         if (parent instanceof JComponent) {
>             ((JComponent)parent).revalidate();
>         }
>         final Window window = SwingUtilities.getWindowAncestor(this);
>         if (window != null) {
>             window.validate();
>         }
>     }
> 
> to the embedded view which is for instance called within draw(), a
> method which is called frameRate(int)-times per second.
> 
> Without the JSplitPane it seems fine, but now I'm adding another view
> side by side and it doesn't work anymore :(
> 
> Well to recap the setup:
> 
> View extends JPane => is inserted in a JSplitPane.
> View embeds a PApplet instance via (add(Component)).
> JSplitPane is inserted in a JPane and added to the contentPane of a
> JFrame instance together with a JMenuBar instance (via
> setJMenuBar(JMenuBar)).
> 
> I'm using Java7.
> 
> johannes at luna:~/workspace/treetank$ java -version
> java version "1.7.0"
> Java(TM) SE Runtime Environment (build 1.7.0-b147)
> Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)
> 
> The setup of the JSplitPane is as follows:
> 
>     /**
>      * Setup of the {@link JSplitPane} reference.
>      *
>      * @param paramPane
>      *            {@link JSplitPane} reference
>      * @param paramTmpView
>      *            {@link JComponent} reference to the left
>      * @param paramView
>      *            {@link JComponent} reference to the right
>      */
>     private void
>         setupPane(final JSplitPane paramPane, final JComponent
> paramTmpView, final JComponent paramView) {
>         assert paramPane != null;
>         assert paramTmpView != null;
>         assert paramView != null;
>         paramPane.setSize(new Dimension(mGUI.getWidth(), mGUI.getHeight()));
>         paramPane.setAlignmentX(mGUI.getWidth() / 2f);
>         paramPane.setAlignmentY(mGUI.getHeight() / 2f);
>         paramPane.setDividerLocation(0.5);
>         paramPane.setContinuousLayout(true);
>         paramPane.setLeftComponent(paramTmpView);
>         paramPane.setRightComponent(paramView);
> 
> paramPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, new
> Listener(paramPane));
>         final Container parent = paramPane.getParent();
>         if (parent instanceof JComponent) {
>             ((JComponent)parent).revalidate();
>         }
>         final Window window = SwingUtilities.getWindowAncestor(this);
>         if (window != null) {
>             window.validate();
>         }
>     }
> 
> I'm not sure, I thing the final code is useless with revalidate() and so on.
> 
> kind regards,
> Johannes



More information about the swing-dev mailing list