English 中文(简体)
各个小组的配量单位
原标题:Align Swing Components across Panels

我们有一个包含多个联合小组的JPanel,其中包括JLabels和JText Boxes。

在每个内部的JPanels,我们使用JGoodies Layout,以确保所有Labels的适当协调。

但我们当然希望所有实验室独立地协调它们所处的次位。

我们如何能够这样做,而没有确定包含“JLabels”一栏的宽度?

由于我们必须在各组成部分之间架设边界线,我们可以放松联合通道。

最佳回答

仅仅因为JPanels 具有边界,就意味着它们实际上需要包含其表面内容。 召集小组透明。 将小组和组成小组的构成部分添加到公布小组。 添加空间部件,以示小组在布局中的 in。 你们还需要放弃“优化绘画”或其中一部分用于重叠部件。

问题回答

我建议支持平整的布局。 单一配置是容易的。 避免标题Borders,代之以“分离者、分离者或仅仅是白色空间”。 这为绝大多数编辑和表格提供了帮助。

但是,如果你想要使多位编辑或表格相互配合,上述技术就失败了。 JGoodies FormLayout为解决这一问题提供了两个层次,更一般而言是提高布局的一致性: (1) 大小限值降低,2) 排外变量。

如果有的话,你可以描述能够确保以各种形式获得最低宽度的布局。 例如,如果你想说所有标签栏至少有100px的宽度,你可以就标签栏说“[100px, pref]”。

2)超越办法1。 动机是从多种形式中提取100皮克。 在表格中,你可以确定布局变量,例如,你认为“[100px, pref]”或“权利:[75dlu, pref]”等。 如果你在各位编辑中使用布局变量,这些变量是前后一致的,而且你有一个可以为所有编辑配置所有标签栏的单一地点。

我知道,这样做没有简单的方法。 你的选择:

  • Write your own layout manager (or extend an existing one) with that capability
  • Fixed column widths
  • Decide that panels that are visually separated by borders don t need to have their contents aligned after all

我宣读了关于使用共同财产而不是多条边界的联产企业的建议,如果把植被同起来是你的优先事项。

JSeparator gives the visual effect of grouping widgets, but themselves are just another simple widget fitting into the same JPanel. Read the tutorial for important tips such as setting the preferred size. http://download.oracle.com/javase/tutorial/uiswing/components/separator.html

而且, Apple果目前的准则只是把空洞空间作为群体之间的隔.,作为边界和分离者的替代。

这一样本守则有助于解决你的统一问题:

//c is instance of the content pane
c.setLayout(gl=new GridLayout(3,0));
//jp is a jpanel. I took this panel because there is no alignment
//setting for a specifiq cell of grid Layout.
jp.setAlignmentX(CENTER_ALIGNMENT);
//jl is the jLabel
jp.add(jl);
//finally I add that with the frame
c.add(jp);

希望将有助于你解决你的问题。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签