<Swing Dev> JSplitPane / heavyweight vs. lightweight components

Pavel Porvatov pavel.porvatov at oracle.com
Tue Jan 17 09:30:17 UTC 2012


Hi Johannes,

Could you please provide a small test that can be run and which shows 
the problem?

Thanks, Pavel
> 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