Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Question about Swing and SWT
Question about Swing and SWT [message #437434] Fri, 04 June 2004 15:03 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Yannick Saillet is currently offline Yannick SailletFriend
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 Go to previous message
Eclipse UserFriend
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
Previous Topic:Problem with Mozilla and Post Requests
Next Topic:Custom SWT components
Goto Forum:
  


Current Time: Thu Apr 25 13:18:53 GMT 2024

Powered by FUDForum. Page generated in 0.03366 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top