Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsSize-Calculation of Embedded Swing Controls in Dialogs
https://www.eclipse.org/forums/index.php/mv/msg/3674/10897/#msg_10897
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();]]>Dominik Kaspar2009-04-06T11:29:22-00:00Re: Size-Calculation of Embedded Swing Controls in Dialogs
https://www.eclipse.org/forums/index.php/mv/msg/3674/10910/#msg_10910
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();
>]]>Gordon Hirsch2009-04-07T14:30:35-00:00Re: Size-Calculation of Embedded Swing Controls in Dialogs
https://www.eclipse.org/forums/index.php/mv/msg/3674/574958/#msg_574958
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();
>]]>Gordon Hirsch2009-04-07T14:30:35-00:00Re: Size-Calculation of Embedded Swing Controls in Dialogs
https://www.eclipse.org/forums/index.php/mv/msg/3674/574984/#msg_574984
-albireo standalone 0.0.3 (v20081031)
-java 1.6.0_12 64-Bit (also tested with 32-Bit)
-standalone swt win32 x86 64-Bit 3.4.1 (also tested with 32-Bit)
-standalone jface 3.4.1
I'm expecting:
-the dialog is big enough to display all JTextFields*
-there should be no scroll bar visible*
*as long the dialog is not resized and the screen resolution is not too
low;)]]>Dominik Kaspar2009-04-08T15:02:17-00:00Re: Size-Calculation of Embedded Swing Controls in Dialogs
https://www.eclipse.org/forums/index.php/mv/msg/3674/10923/#msg_10923
-albireo standalone 0.0.3 (v20081031)
-java 1.6.0_12 64-Bit (also tested with 32-Bit)
-standalone swt win32 x86 64-Bit 3.4.1 (also tested with 32-Bit)
-standalone jface 3.4.1
I'm expecting:
-the dialog is big enough to display all JTextFields*
-there should be no scroll bar visible*
*as long the dialog is not resized and the screen resolution is not too
low;)]]>Dominik Kaspar2009-04-08T15:02:17-00:00Re: Size-Calculation of Embedded Swing Controls in Dialogs
https://www.eclipse.org/forums/index.php/mv/msg/3674/575004/#msg_575004
size of the Swing component is not yet known when the dialog decides on
its own initial size. (It's not yet known because size calculations
involve waiting for the AWT event dispatch thread to run. We defer
actual layout of the SWT composite until this has happened, but this is
a case where just a size computation is done, and it probably can't be
deferred.)
One solution for you would be to override your TitleAreaDialog's
getInitialSize() method and return a reasonable value that does not rely
on waiting for the Swing component's preferred size to be known.
If that won't work, you could try to find a way to resize the dialog
once the Swing control's preferred size has been calculated. I'm not
sure how easy that would be.
Dominik Kaspar wrote:
> I'm using the following environment:
> -albireo standalone 0.0.3 (v20081031)
> -java 1.6.0_12 64-Bit (also tested with 32-Bit)
> -standalone swt win32 x86 64-Bit 3.4.1 (also tested with 32-Bit)
> -standalone jface 3.4.1
>
> I'm expecting:
> -the dialog is big enough to display all JTextFields*
> -there should be no scroll bar visible*
>
> *as long the dialog is not resized and the screen resolution is not too
> low;)
>]]>Gordon Hirsch2009-04-08T19:47:46-00:00Re: Size-Calculation of Embedded Swing Controls in Dialogs
https://www.eclipse.org/forums/index.php/mv/msg/3674/10934/#msg_10934
size of the Swing component is not yet known when the dialog decides on
its own initial size. (It's not yet known because size calculations
involve waiting for the AWT event dispatch thread to run. We defer
actual layout of the SWT composite until this has happened, but this is
a case where just a size computation is done, and it probably can't be
deferred.)
One solution for you would be to override your TitleAreaDialog's
getInitialSize() method and return a reasonable value that does not rely
on waiting for the Swing component's preferred size to be known.
If that won't work, you could try to find a way to resize the dialog
once the Swing control's preferred size has been calculated. I'm not
sure how easy that would be.
Dominik Kaspar wrote:
> I'm using the following environment:
> -albireo standalone 0.0.3 (v20081031)
> -java 1.6.0_12 64-Bit (also tested with 32-Bit)
> -standalone swt win32 x86 64-Bit 3.4.1 (also tested with 32-Bit)
> -standalone jface 3.4.1
>
> I'm expecting:
> -the dialog is big enough to display all JTextFields*
> -there should be no scroll bar visible*
>
> *as long the dialog is not resized and the screen resolution is not too
> low;)
>]]>Gordon Hirsch2009-04-08T19:47:46-00:00Re: Size-Calculation of Embedded Swing Controls in Dialogs
https://www.eclipse.org/forums/index.php/mv/msg/3674/575024/#msg_575024
swing components. To pre calculate the size of the components will be a
lot of effort. Therefore I tried to put my swing components into a frame
(without displaying it), pack the components, get the size and remove the
components from the frame. Unfortunatly I had to do this in the SWT thread
before the Swing thread is used for really creating the components. You
can imagine that this leads into problems;) Is it possible to put the
'swing pre creation and packing' into a sync swing thread?
The second solution could be a work around. The problem there is that you
can see the dialog, when it pupups, in the wrong size for a short moment
before it resizes to the correct size. The problem here is really to find
the correct moment to set the size and I don't know how to figure out when
the size calculation of the swing componetns is successfully finished.
Thanks, Dominik]]>Dominik Kaspar2009-04-14T09:15:43-00:00Re: Size-Calculation of Embedded Swing Controls in Dialogs
https://www.eclipse.org/forums/index.php/mv/msg/3674/10944/#msg_10944
swing components. To pre calculate the size of the components will be a
lot of effort. Therefore I tried to put my swing components into a frame
(without displaying it), pack the components, get the size and remove the
components from the frame. Unfortunatly I had to do this in the SWT thread
before the Swing thread is used for really creating the components. You
can imagine that this leads into problems;) Is it possible to put the
'swing pre creation and packing' into a sync swing thread?
The second solution could be a work around. The problem there is that you
can see the dialog, when it pupups, in the wrong size for a short moment
before it resizes to the correct size. The problem here is really to find
the correct moment to set the size and I don't know how to figure out when
the size calculation of the swing componetns is successfully finished.
Thanks, Dominik]]>Dominik Kaspar2009-04-14T09:15:43-00:00Re: Size-Calculation of Embedded Swing Controls in Dialogs
https://www.eclipse.org/forums/index.php/mv/msg/3674/575103/#msg_575103
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();]]>Dominik Kaspar2009-05-14T09:33:30-00:00Re: Size-Calculation of Embedded Swing Controls in Dialogs
https://www.eclipse.org/forums/index.php/mv/msg/3674/10976/#msg_10976
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();]]>Dominik Kaspar2009-05-14T09:33:30-00:00