llm*_*llm 5 java user-interface components
我使用以下内容:
java.awt.Container.add(Component comp, Object constraints)
Run Code Online (Sandbox Code Playgroud)
我如何具体约束对象?我需要能够在容器中放置一个组件.
哦,JInternalFrame如果这有助于我的课程延伸......
我需要指定坐标以将组件放在容器中
这些constraints对象取决于您使用的布局管理器。
例如,使用 aBorderLayout你将只有一些常量:container.add(element, BorderLayout.CENTER)
如果容器的布局管理器是 a,GridBagLayout您将拥有一个GridBagConstraints具有指定参数的对象。
一些布局管理器(例如FlowLayout或GridLayout)不需要任何类型的约束,因为它们实际上决定如何自行放置事物。
附带说明一下,如果您需要绝对定位,则不会有任何布局管理器:
container.setLayout(null);
container.add(element1);
Insets insets = pane.getInsets();
element1.setBounds(..); //here you set absolute position
Run Code Online (Sandbox Code Playgroud)