简体   繁体   中英

Overlap Components When Using ComponentResizer

I want to make my jTable expandable while floating/overlay when dragging it using ComponentResizer class. I'm using ComponentResizer class from Rob Camick.

Currently as below after dragging the table:

在此处输入图片说明

I tried change my layout to null but the result still same. In my code, I just added to call the ComponentResizer class:

ComponentResizer cr = new ComponentResizer();
cr.setSnapSize(new Dimension(10, 10));
cr.registerComponent(jScrollPane2);

I expect the dragging table will float and overlay the components below it.

Swing is designed to paint components in 2D space, not 3D space.

So when components are added to the same panel, Swing will paint components in the reverse order the component is added to the panel. In your case it looks like you add the components to the panel before adding the scrollpane to the panel.

So you could:

  1. reverse the order in which you add the components to the panel
  2. use the setComponentZOrder(...) method on the scrollpane to set its value to 0, so it is painted last.

However, this will still cause a problem because if you hover over the button the button will appear because its border is changed. This is because Swing assumes 2D layouts not 3D. If you want to make sure the table is always painted over the button you need to override the isOptimizedDrawingEnable() method of the panel. See Overlap Layout for more information on ZOrder painting.

我通过将所有组件放在一个分层的窗格中并使用“边框布局”解决了该问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM