Question about Swing and SWT [message #437434] |
Fri, 04 June 2004 15:03 |
Eclipse User |
|
|
|
Originally posted by: "prenom.,nom".sextant.thomson-csf.com
I'm doing the migration of a Swing application. It was a JFrame with a JMenuBar
and panels.
Actually, I've created a Shell, with an embedded Frame containing all the Swing
panels.
I'm going to migrate the JMenuBar in SWT, in order to set it to the Shell. The
problem I have is the use of Actions. In my panels, I have components which use
Swing Action. And in my future SWT MenuBar, I'll have MenuItems which should use
similar actions. For example, the MenuItem "Save" and the JButton "Save" have
the same action.
Do SWT components support Swing actions? Or am I forced to migrate all in SWT?
I hope you'll be able to help me.
Thank you in advance.
Fabrice
|
|
|
Re: Question about Swing and SWT [message #437476 is a reply to message #437434] |
Fri, 04 June 2004 16:09 |
Yannick Saillet Messages: 24 Registered: July 2009 |
Junior Member |
|
|
Hi Fabrice,
you can easily write a generic SWT SelectionListener which triggers the
actionPerformed() method of your Swing action and attach it to the menu.
The easiest is probably to write an helper method creating the menu item
from the action:
public static MenuItem createMenuItem(Menu parent, int style, final Action
action)
{
MenuItem item = new MenuItem(parent, style);
String name = action.getValue(Action.NAME);
if (name!=null) item.setText(name);
// ...
// do the same to assign mnemonic, icons, etc...
item.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
action.actionPerformed(null);
}
});
}
Then use this helper method to create the menu items, instead of using the
constructor.
I hope it helps...
Yannick
NOM Prenom wrote:
> I'm doing the migration of a Swing application. It was a JFrame with a
> JMenuBar and panels.
> Actually, I've created a Shell, with an embedded Frame containing all the
> Swing panels.
> I'm going to migrate the JMenuBar in SWT, in order to set it to the Shell.
> The problem I have is the use of Actions. In my panels, I have components
> which use Swing Action. And in my future SWT MenuBar, I'll have MenuItems
> which should use similar actions. For example, the MenuItem "Save" and the
> JButton "Save" have the same action.
> Do SWT components support Swing actions? Or am I forced to migrate all in
> SWT?
>
> I hope you'll be able to help me.
>
> Thank you in advance.
>
> Fabrice
|
|
|
Re: Question about Swing and SWT [message #437582 is a reply to message #437476] |
Tue, 08 June 2004 08:16 |
Eclipse User |
|
|
|
Originally posted by: "prenom.,nom".sextant.thomson-csf.com
Merci pour ton aide Yannick!
Je vais essayer de mettre en place ce système.
Fabrice
Yannick Saillet a écrit :
>
> Hi Fabrice,
>
> you can easily write a generic SWT SelectionListener which triggers the
> actionPerformed() method of your Swing action and attach it to the menu.
> The easiest is probably to write an helper method creating the menu item
> from the action:
>
> public static MenuItem createMenuItem(Menu parent, int style, final Action
> action)
> {
> MenuItem item = new MenuItem(parent, style);
> String name = action.getValue(Action.NAME);
> if (name!=null) item.setText(name);
>
> // ...
> // do the same to assign mnemonic, icons, etc...
>
> item.addSelectionListener(new SelectionAdapter()
> {
> public void widgetSelected(SelectionEvent e)
> {
> action.actionPerformed(null);
> }
> });
> }
>
> Then use this helper method to create the menu items, instead of using the
> constructor.
>
> I hope it helps...
>
> Yannick
>
> NOM Prenom wrote:
>
> > I'm doing the migration of a Swing application. It was a JFrame with a
> > JMenuBar and panels.
> > Actually, I've created a Shell, with an embedded Frame containing all the
> > Swing panels.
> > I'm going to migrate the JMenuBar in SWT, in order to set it to the Shell.
> > The problem I have is the use of Actions. In my panels, I have components
> > which use Swing Action. And in my future SWT MenuBar, I'll have MenuItems
> > which should use similar actions. For example, the MenuItem "Save" and the
> > JButton "Save" have the same action.
> > Do SWT components support Swing actions? Or am I forced to migrate all in
> > SWT?
> >
> > I hope you'll be able to help me.
> >
> > Thank you in advance.
> >
> > Fabrice
|
|
|
Powered by
FUDForum. Page generated in 0.03366 seconds