如何停止JFace组合框从窗口大小调整大小? [英] How to stop JFace combo box from re sizing on a window re size?

查看:401
本文介绍了如何停止JFace组合框从窗口大小调整大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java Eclipse RCP程序,其中在JFace组合框中有一个长字符串。现在当我在同一个视图,组合框附加一个滚动它,以显示全名。但是一旦我调整应用程序的窗口大小,组合框就伸展自身以适应冗长的字符串。

I have a Java Eclipse RCP program in which I have a a long string inside a JFace combobox. Now when I am in the same view,The combobox attaches a scroll over it to show the full name. but as soon as I re size the window of the application, the combobox stretches itself to accommodate the lengthy string.

如何使组合框保持相同的大小。像它的大小应该保持固定,即使我调整窗口大小后。这里有两个屏幕截图来演示这个问题。

How do i make the combobox stay the same size. Like the size of it should remain fixed even after I resize the window. Here are two screen shots to demonstrate the issue.

我使用comboViewer和里面的comboBox。

P.S. I am using a comboViewer and inside it a comboBox.

提前感谢。

推荐答案

如果您使用 GridLayout GridData 作为布局, widthHint 字段建议Combo的宽度。

If you are using GridLayout and GridData as your layout you can specify a value in the widthHint field to suggest the width for the Combo.

GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);

data.widthHint = 100;

preferredResourceCombo.setLayoutData(data);

如果用户使用大字体,使用这样的固定值可能会导致问题。因此,计算宽度的另一种方法是使用 Dialog.convertWidthInCharsToPixels

Using a fixed value like this might cause problems if the user uses a large font. So an alternative way of calculating the width is to use Dialog.convertWidthInCharsToPixels:

GC gc = new GC(control);
gc.setFont(control.getFont());
FontMetrics fontMetrics = gc.getFontMetrics();
gc.dispose();

data.widthHint = Dialog.convertWidthInCharsToPixels(fontMetrics, charCount);

如果您的代码位于 Dialog 可以简化为:

If your code is in a Dialog you can simplify this to just:

data.widthHint = convertWidthInCharsToPixels(charCount);

这篇关于如何停止JFace组合框从窗口大小调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆