[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.technology.albireo] Re: Size-Calculation of Embedded Swing Controls in Dialogs
|
I solved the problem by adding a SizeListener to the SwingControl which is
called after the Swing/AWT size calculation is finished. There I just set
the size on the shell again. It's a little bit ugly here that you can see
the shell resizing on the screen. I tried to set an initial size of
Point(0,0) but the shell has some min size for the title and close, min,
max buttons. Any ideas?
Thanks and regards
Dominik
Example code:
TitleAreaDialog d = new TitleAreaDialog(topLevelShell) {
protected Control createDialogArea(final Composite parent) {
Composite comp = (Composite) super.createDialogArea(parent);
SwingControl control = new SwingControl(comp, SWT.NONE) {
protected JComponent createSwingComponent() {
JPanel p = new JPanel();
p.setLayout(new java.awt.GridLayout(10, 1));
for (int i = 0; i < 10; i++) {
p.add(new JTextField(String.valueOf(i)));
}
JScrollPane scroll = new JScrollPane(p);
scroll.setBorder(new EmptyBorder(0, 0, 0, 0));
return scroll;
}
public Composite getLayoutAncestor() {
return parent;
}
};
control.setLayoutData(new GridData(GridData.FILL_BOTH));
control.addSizeListener(new SizeListener() {
private boolean packed = false;
public void preferredSizeChanged(SizeEvent event) {
if (!packed) {
Point size = getInitialSize();
getShell().setSize(size);
packed = true;
}
}
});
return parent;
}
};
d.open();