Size-Calculation of Embedded Swing Controls in Dialogs [message #10897] |
Mon, 06 April 2009 11:29 |
Dominik Kaspar Messages: 12 Registered: July 2009 |
Junior Member |
|
|
Hi,
If I'm using a JFace dialog like the TitleAreaDialog and having a
SwingControl inside the dialog, the size of the main panel is not
correctly calculated after the shell of the dialog is created.
I tried all available Composites for the layoutDeferredAncestor, but no
one was working correctly. My workaround was to call pack() on the shell
in the afterComponentCreatedSWTThread() method but this works only
randomly.
Any ideas to solve this problem?
Thanks,
Dominik
TitleAreaDialog d = new TitleAreaDialog(topLevelShell) {
protected Control createDialogArea(Composite parent) {
final 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 getShell();
}
};
control.setLayoutData(new GridData(GridData.FILL_BOTH));
return parent;
}
};
d.open();
|
|
|
Re: Size-Calculation of Embedded Swing Controls in Dialogs [message #10910 is a reply to message #10897] |
Tue, 07 April 2009 14:30 |
Gordon Hirsch Messages: 100 Registered: July 2009 |
Senior Member |
|
|
The code you included below works fine for me. What version of Java are
you using? Could you be more specific about the way in which the size is
not correctly calculated?
Dominik Kaspar wrote:
> Hi,
>
> If I'm using a JFace dialog like the TitleAreaDialog and having a
> SwingControl inside the dialog, the size of the main panel is not
> correctly calculated after the shell of the dialog is created.
>
> I tried all available Composites for the layoutDeferredAncestor, but no
> one was working correctly. My workaround was to call pack() on the shell
> in the afterComponentCreatedSWTThread() method but this works only
> randomly.
>
> Any ideas to solve this problem?
>
> Thanks,
> Dominik
>
> TitleAreaDialog d = new TitleAreaDialog(topLevelShell) {
> protected Control createDialogArea(Composite parent) {
> final 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 getShell();
> }
> };
> control.setLayoutData(new GridData(GridData.FILL_BOTH));
> return parent;
> }
> };
> d.open();
>
|
|
|
|
|
|
|
Re: Size-Calculation of Embedded Swing Controls in Dialogs [message #574958 is a reply to message #10897] |
Tue, 07 April 2009 14:30 |
Gordon Hirsch Messages: 100 Registered: July 2009 |
Senior Member |
|
|
The code you included below works fine for me. What version of Java are
you using? Could you be more specific about the way in which the size is
not correctly calculated?
Dominik Kaspar wrote:
> Hi,
>
> If I'm using a JFace dialog like the TitleAreaDialog and having a
> SwingControl inside the dialog, the size of the main panel is not
> correctly calculated after the shell of the dialog is created.
>
> I tried all available Composites for the layoutDeferredAncestor, but no
> one was working correctly. My workaround was to call pack() on the shell
> in the afterComponentCreatedSWTThread() method but this works only
> randomly.
>
> Any ideas to solve this problem?
>
> Thanks,
> Dominik
>
> TitleAreaDialog d = new TitleAreaDialog(topLevelShell) {
> protected Control createDialogArea(Composite parent) {
> final 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 getShell();
> }
> };
> control.setLayoutData(new GridData(GridData.FILL_BOTH));
> return parent;
> }
> };
> d.open();
>
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05037 seconds