The following program shows two differences between the two platforms (I'm not sure if these have a common cause, but they both cause us a problem).
First, if the program is compiled as-is, then on GTK, the labels containing the text are wrapped, but on Windows they're not. I don't know how the GTK version decides where to wrap the lines, but it seems pretty acceptable.
Second, in both cases the window you get is much larger than necessary, with the controls bunched up in the top left corner, and empty space in the bottom right. Fair enough, there's no specific size mentioned in the program. But if you uncomment the "shell.pack()" call, then with GTK, the window gets shown at a sensible size (just large enough to contain the components). On Windows, the call to "pack" has no obvious effect (you still end up with a huge window).
Incidentally, using SWT designer (which I'm doing on Linux/GTK), neither design nor "preview" mode appears takes no account of the "pack" call, and although the "preview" shows the labels wrapped, the designer doesn't (they just show up as truncated).
I can provide screenshots of any of the above if it helps.
Developing on Linux GTK using Eclipse 3.0.2
WindowBuilderPro 4.0.0 compiled on 2005.05.06 for Eclipse 3.0.0
thanks for any suggestions
nick
- Code: Select all
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class AutoSize {
private Button okButton;
protected Shell shell;
private Text refreshTimeText;
int finalValue = 10;
public static void main(String[] args) {
try {
AutoSize window = new AutoSize();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
final Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
protected void createContents() {
shell = new Shell(SWT.CLOSE | SWT.RESIZE);
final GridLayout gridLayout = new GridLayout();
gridLayout.verticalSpacing = 6;
gridLayout.numColumns = 3;
gridLayout.marginWidth = 12;
gridLayout.marginHeight = 12;
gridLayout.horizontalSpacing = 6;
shell.setLayout(gridLayout);
Label t = new Label(shell, SWT.WRAP);
t.setText("In this dialog box you can type in a value, but the OK button will only be enabled if the value you type is at least 5.");
GridData gd = new GridData();
gd.horizontalSpan = 3;
t.setLayoutData(gd);
t = new Label(shell, SWT.WRAP);
t.setText("So feel free to type in a number, any number. Don't type things that aren't numbers though, as they're not acceptable.");
gd = new GridData();
gd.horizontalSpan = 3;
t.setLayoutData(gd);
new Label(shell, SWT.NONE).setText("Number:");
refreshTimeText = new Text(shell, SWT.BORDER);
refreshTimeText.setToolTipText("Enter a value between 5 and 100");
refreshTimeText.setText("10");
Point p = refreshTimeText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
gd = new GridData();
gd.widthHint = p.x;
refreshTimeText.setLayoutData(gd);
refreshTimeText.setText("" + finalValue);
refreshTimeText.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent e) {
e.doit = false;
String text = ((Text) e.widget).getText();
char c = e.character;
// Allow digits.
//
if (Character.isDigit(c) ) {
e.doit = true;
}
// Allow DEL and backspace.
//
else if ( c == '\b' || c == 0x7f ) {
e.doit = true;
}
}
});
// Enable/disable the OK button depending on whether the text field
// contains a time within the valid range
refreshTimeText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
try {
String text = ((Text)e.widget).getText();
finalValue = Integer.parseInt(text);
}
catch (Exception ex) {
finalValue = -1;
}
okButton.setEnabled((finalValue >= 5) && (finalValue < 100));
}
});
new Label(shell, SWT.NONE).setText("seconds");
shell.setText("SWT Application");
okButton = new Button(shell, SWT.NONE);
okButton.setText("OK");
// On Linux/GTK, this makes the window size itself in a sensible way
// but on Win32 it seems to have no effect
// shell.pack();
}
}