我需要在 Swing 中选择一个标准容器(JPanel?),我可以将其用作占位符,我可以向其中添加另一个扩展 JPanel 的自定义组件:
JPanel containerPanel;
// built by a library from a text file, automatically part of a nice layout
MyPanel componentPanel;
// something complicated that I can't integrate with the builder library
containerPanel = builder.getMyContainerPanel();
componentPanel = new MyPanel(...);
containerPanel.add(componentPanel);
有没有办法以某种方式耦合两个面板尺寸,以便调整大小正常工作?我不太确定在摇摆中调整大小是如何工作的,但我想要的是外部containerPanel
是一个薄的包装器,它服从于我componentPanel
的和外部面板尽可能多地委托给内部面板。
我不想以这种方式做事,但这似乎是将构建器库与我的自定义组件分离的最佳方式。