- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用程序有一个带有两个子项的 SashForm。我希望在调整窗口大小时左 child 保持相同的大小。我想要 Eclipse 对 Package Explorer 和主编辑器做同样的事情。当您调整窗口大小时,只有文本编辑器会更改大小。但是,Package Explorer 仍然可以通过窗框调整大小。
我尝试使用以下内容
sashForm.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
int width = sashForm.getClientArea().width;
int[] weights = sashForm.getWeights();
weights[1] = width - weights[0];
sashForm.setWeights(weights);
}
});
问题是左侧尺寸的宽度要么缩小到 0,要么扩大太多。看起来权重在调用之前已经更新了。
如果我将权重[0]设置为等于某个常量,它就会达到我想要的效果。
最佳答案
我设法运行了一个示例,它应该可以让您了解如何解决您的问题。问题是,SashForm
使用权重而不是像素。因此,您必须根据父级大小计算左子级必须占据的百分比,并将其余的分配给右子级。
在我的代码示例中,您可以指定左子元素的宽度并为右子元素设置最小尺寸,这样 SashForm
将始终显示两者。
private static final int MIN_WIDTH_LEFT = 100;
private static final int MIN_WIDTH_RIGHT = 50;
public static void main(String[] args)
{
Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new FillLayout());
final SashForm form = new SashForm(shell, SWT.HORIZONTAL);
Button button = new Button(form, SWT.PUSH);
button.setText("Left");
Button buttonR = new Button(form, SWT.PUSH);
buttonR.setText("Right");
form.setWeights(new int[] {1, 2});
shell.addListener(SWT.Resize, new Listener()
{
@Override
public void handleEvent(Event arg0)
{
int width = shell.getClientArea().width;
int[] weights = form.getWeights();
if(width >= MIN_WIDTH_LEFT + MIN_WIDTH_RIGHT)
{
weights[0] = 1000000 * MIN_WIDTH_LEFT / width;
weights[1] = 1000000 - weights[0];
}
else
{
weights[0] = 1000000 * MIN_WIDTH_LEFT / (MIN_WIDTH_LEFT + MIN_WIDTH_RIGHT);
weights[1] = 1000000 * MIN_WIDTH_RIGHT / (MIN_WIDTH_LEFT + MIN_WIDTH_RIGHT);
}
System.out.println(width + " " + Arrays.toString(weights));
form.setWeights(weights);
}
});
shell.pack();
shell.setSize(600, 400);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
这就是它的样子:
启动:
调整大小后:
当减小窗口尺寸直到它太小而无法显示两个最小尺寸时:
正如您在本例中所看到的,左侧子级的最小尺寸将被忽略,以便仍然能够显示两个子级。
关于java - 等宽窗扇,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17227086/
如果图像的宽度和高度相等,我如何添加类“相等”。 这是我的代码: var img = $('img', this); var width = img.width(); var height = img
任何人都可以告诉我涵盖大部分 unicode 字符的等宽字体吗?如果没有,那么包含大部分欧洲语言字符集的等宽字体? 最佳答案 我也在寻找单色空间、丰富的 Unicode 字体。到目前为止,我使用 De
我编写了一个程序来拍摄照片并创建 ASCII 表示(ASCII 艺术)。起初,我将 ASCII 字符串写入控制台,但现在我有了一个保存文本的 JLabel。但是,JLabel 输出是不规则的,不像控制
如果我有生成的列表 我要分成几列 like this是否有可能以某种方式让列与最宽的列一样宽 . 我有一个下拉导航,目前我在 上只有一个固定宽度s 但对于较小的导航元素,如“常见问题解答”,有很多
我对编程很陌生。 我试图让三个 col-md-4 具有相同的宽度。我假设如果在 HTML 中正确引用了 Bootstrap,则不需要 CSS。任何建议将不胜感激。 代码: /*NAV LOGO*/ .
是否可以像这样制作一个纯 CSS 解决方案: 元素有一些最小宽度。 它们应该动态增长以填充所有容器宽度,然后换行 列表中的所有元素都应具有相同的宽度。 现在是这样的: 这也是我希望它看起来像的样子(我
我正在尝试通过 flexbox 创建三行,其中将包含可变数量的列(顶部和底部的行将在数量上匹配)和一个中间列,它只是一个列。 由于列数是可变的,因此父级上没有设置宽度。 我正在努力让中间列的宽度与顶部
是否可以像这样制作一个纯 CSS 解决方案: 元素有一些最小宽度。 它们应该动态增长以填充所有容器宽度,然后换行 列表中的所有元素都应具有相同的宽度。 现在是这样的: 这也是我希望它看起来像的样子(我
我将对象动态添加到面板,然后添加到我的边框布局。我需要西部、中心和东部的大小都相等。这是我目前所拥有的: static int width = 300;//Screen width static in
我有一列 4 个元素。由于内容不同,所有元素的宽度都不同。使用 flexbox,有谁知道如何使所有元素与最大元素的宽度相同,同时保持它们全部居中? 这是我目前拥有的。 .container { d
我正在创建一个表单,我有 2 个并排的 div。这是我当前的 html: First name Middle n
如何并排排列 3 个 UIButton。我正在使用自动布局。我的要求是: 1.无论设备如何,它们都应该是等宽的 2.从 View 的开始到结束垂直占据 我尝试了不同的方法,我没能实现。是否可以通过界面
我在 flexbox 中使用 box-sizing: border-box; 具有不同的 border 厚度。我希望 flexbox 中的元素具有相等的宽度,但它会计算没有边框的元素的 width。
我在 flexbox 中使用 box-sizing: border-box; 具有不同的 border 厚度。我希望 flexbox 中的元素具有相等的宽度,但它会计算没有边框的元素的 width。
我是一名优秀的程序员,十分优秀!