Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Image inside push button
Image inside push button [message #450386] Fri, 11 February 2005 11:57 Go to next message
Eclipse UserFriend
Originally posted by: danny.g2k.es

Hi List.

I have a simple shell with two push button. When i try to run my app
inside PDA i can´t see the button with image inside. On PC all works ok.
Here is a segment of my code.

/**
* This method initializes sShell
*/
private void createShell() {
mainShell = new Shell(SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
ImageLoader imagesResources = ImageLoader.getInstance();
clienteButton = new Button(mainShell, SWT.NONE);
articuloButton = new Button(mainShell, SWT.NONE);

clienteButton.setImage(imagesResources.stockImages[imagesRes ources.cmdCliente]);
articuloButton.setImage(imagesResources.stockImages[imagesRe sources.cmdArticulo]);


}

Thanks Danny
Re: Image inside push button [message #450389 is a reply to message #450386] Fri, 11 February 2005 12:37 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 92
Registered: July 2009
Member
You can't use images inside buttons in the PocketPC. You need to use a label
instead. I'm working on the same kind of thing at the moment. You need to
register an event on the label for the click.

On the subject, if anyone has a nice code snippet of a Label with an image,
used as a button, on the pocket pc I'd like to see it. Can we have a nice
effect for the button pressed state too please :-)

Andy


"Danny Garcia Hernandez" <danny@g2k.es> wrote in message
news:cui6ij$on4$1@www.eclipse.org...
> Hi List.
>
> I have a simple shell with two push button. When i try to run my app
> inside PDA i can
Re: Image inside push button [message #450442 is a reply to message #450389] Sat, 12 February 2005 12:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: danny.g2k.es

Hi Andy, if i caný use button on pocket pc maybe toolbar can simulate my
applications buttons with image.

Thank
Danny

Andy Harrison wrote:
> You can't use images inside buttons in the PocketPC. You need to use a label
> instead. I'm working on the same kind of thing at the moment. You need to
> register an event on the label for the click.
>
> On the subject, if anyone has a nice code snippet of a Label with an image,
> used as a button, on the pocket pc I'd like to see it. Can we have a nice
> effect for the button pressed state too please :-)
>
> Andy
>
>
> "Danny Garcia Hernandez" <danny@g2k.es> wrote in message
> news:cui6ij$on4$1@www.eclipse.org...
>
>>Hi List.
>>
>>I have a simple shell with two push button. When i try to run my app
>>inside PDA i can´t see the button with image inside. On PC all works ok.
>>Here is a segment of my code.
>>
>>/**
>>* This method initializes sShell
>>*/
>>private void createShell() {
>>mainShell = new Shell(SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
>>ImageLoader imagesResources = ImageLoader.getInstance();
>>clienteButton = new Button(mainShell, SWT.NONE);
>>articuloButton = new Button(mainShell, SWT.NONE);
>>
>>
>
> clienteButton.setImage(imagesResources.stockImages[imagesRes ources.cmdClient
> e]);
>
> articuloButton.setImage(imagesResources.stockImages[imagesRe sources.cmdArtic
> ulo]);
>
>>
>>}
>>
>>Thanks Danny
>
>
>
Re: Image inside push button [message #450485 is a reply to message #450442] Mon, 14 February 2005 09:51 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 92
Registered: July 2009
Member
yes, i think you are right, if toolbar suits you. You'd have to customise
the toolbar in some way i'd expect depending on your application, but I'm
not the person to ask as I haven't tried that solution either. I think it
would be nice to see some examples anyway, so I'll post my solution and you
can post one too if you like.

Andy

"Danny Garcia Hernandez" <danny@g2k.es> wrote in message
news:cuks18$cfd$1@www.eclipse.org...
> Hi Andy, if i can
Re: Image inside push button [message #450490 is a reply to message #450485] Mon, 14 February 2005 11:38 Go to previous messageGo to next message
Stefan Pietsch is currently offline Stefan PietschFriend
Messages: 68
Registered: July 2009
Member
Hi Andy and Danny,

to use a toolbar do not solve the problem, too. On PocketPC there are no
buttons with an image!

I wrote a new widget to solve the problem. Use the attached class.

Bye Stefan

"Andy Harrison" <andyh@agaricus.co.uk> schrieb im Newsbeitrag
news:cupscd$8mt$1@www.eclipse.org...
> yes, i think you are right, if toolbar suits you. You'd have to customise
> the toolbar in some way i'd expect depending on your application, but I'm
> not the person to ask as I haven't tried that solution either. I think it
> would be nice to see some examples anyway, so I'll post my solution and
you
> can post one too if you like.
>
> Andy
>
> "Danny Garcia Hernandez" <danny@g2k.es> wrote in message
> news:cuks18$cfd$1@www.eclipse.org...
> > Hi Andy, if i can
Re: Image inside push button [message #450492 is a reply to message #450490] Mon, 14 February 2005 11:45 Go to previous messageGo to next message
Stefan Pietsch is currently offline Stefan PietschFriend
Messages: 68
Registered: July 2009
Member
Here is the code:

package tools;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.TypedListener;

public class ImageButton extends Canvas {

private Image image;
private boolean selected;
private boolean paintSelected;
private boolean inMouseEvent;

public ImageButton(Composite parent, int style) {
super(parent, style);

addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
ImageButton.this.paintControl(e);
}
});
addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
ImageButton.this.mouseDown(e);
}
public void mouseUp(MouseEvent e) {
ImageButton.this.mouseUp(e);
}
});
addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
ImageButton.this.mouseMove(e);
}
});
}

void paintControl(PaintEvent e) {
// Zunaest den Hintergrund fuellen
Rectangle r = getClientArea();
r.width -= 1;
r.height -= 1;
e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_WIDGET _BACKGROUND));
e.gc.fillRectangle(r);

// einen Rahmen zeichnen
e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_WIDGET _BORDER));
e.gc.drawRectangle(r);
r.x += 1;
r.y += 1;
r.width -= 1;
r.height -= 1;

if (paintSelected) {
// ein normaler Schatten rund herum
r.width -= 1;
r.height -= 1;

e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_WIDGET _NORMAL_SHADOW))
;
e.gc.drawRectangle(r);
r.x += 1;
r.y += 1;

// oben und links ein heller Schatten

e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_WIDGET _LIGHT_SHADOW));
e.gc.drawLine(r.x, r.y, r.x, r.height);
e.gc.drawLine(r.x, r.y, r.width, r.y);
r.x += 1;
r.y += 1;
}
else {
// unten und rechts ein dunkler Schatten

e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_WIDGET _DARK_SHADOW));
e.gc.drawLine(r.width, r.height, r.x, r.height);
e.gc.drawLine(r.width, r.height, r.width, r.x);
r.width -= 1;
r.height -= 1;

// unten und rechts eine normaler Schatten

e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_WIDGET _NORMAL_SHADOW))
;
e.gc.drawLine(r.width, r.height, r.x, r.height);
e.gc.drawLine(r.width, r.height, r.width, r.x);

// oben und links ein sehr heller Schatten

e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_WIDGET _HIGHLIGHT_SHADO
W));
e.gc.drawLine(r.x, r.y, r.x, r.height);
e.gc.drawLine(r.x, r.y, r.width, r.y);
r.x += 1;
r.y += 1;
r.width -= 1;
r.height -= 1;
}

// Das innere Image zeichen
Rectangle oldClipping = e.gc.getClipping();
e.gc.setClipping(r);
e.gc.drawImage(image, r.x, r.y);
e.gc.setClipping(oldClipping);
}

void mouseDown(MouseEvent e) {
inMouseEvent = true;
redrawWidget(!selected);
}

void mouseUp(MouseEvent e) {
inMouseEvent = false;
redrawWidget(selected);
if (inWidget(e.x, e.y)) {
Event event = new Event();
event.widget = this;
event.item = this;
event.x = e.x;
event.y = e.y;
notifyListeners(SWT.Selection, event);
}
}

void mouseMove(MouseEvent e) {
if (inMouseEvent) {
if (inWidget(e.x, e.y)) {
redrawWidget(!selected);
}
else {
redrawWidget(selected);
}
}
}

void redrawWidget(boolean aPaintSelected) {
if (paintSelected != aPaintSelected) {
paintSelected = aPaintSelected;
redraw();
}
}

public Point computeSize(int wHint, int hHint, boolean changed) {
int width = 0;
int height = 0;

if (image != null) {
Rectangle r = image.getBounds();
width = r.width;
height = r.height;
}

if (wHint != SWT.DEFAULT) {
width = wHint;
}
if (hHint != SWT.DEFAULT) {
height = hHint;
}

return new Point(width+5, height+5);
}

public boolean inWidget(int x, int y) {
Rectangle r = getBounds();
r.x = 0;
r.y = 0;
return r.contains(x, y);
}

public void setImage(Image aImage) {
image = aImage;
redraw();
}

public Image getImage() {
return image;
}

public void setSelection(boolean aSelected) {
if (selected != aSelected) {
selected = aSelected;
redrawWidget(selected);
}
}

public boolean getSelection() {
return selected;
}

public void addSelectionListener(SelectionListener listener) {
addListener(SWT.Selection, new TypedListener(listener));
}

public void removeSelectionListener(SelectionListener listener) {
removeListener(SWT.Selection, listener);
}

public static Rectangle calcScale(Rectangle source, Rectangle destination)
{
double factor = ((double)destination.width)/source.width;

int width;
int height = (int) (source.height * factor);
if (height <= destination.height) {
width = destination.width;
}
else {
factor = ((double)destination.height)/source.height;
width = (int) (source.width * factor);
height = destination.height;
}

return new Rectangle((destination.width-width)/2,
(destination.height-height)/2, width, height);
}
}



"Stefan Pietsch" <pietsch@multichart.de> schrieb im Newsbeitrag
news:cuq2jl$58f$1@www.eclipse.org...
> Hi Andy and Danny,
>
> to use a toolbar do not solve the problem, too. On PocketPC there are no
> buttons with an image!
>
> I wrote a new widget to solve the problem. Use the attached class.
>
> Bye Stefan
>
> "Andy Harrison" <andyh@agaricus.co.uk> schrieb im Newsbeitrag
> news:cupscd$8mt$1@www.eclipse.org...
> > yes, i think you are right, if toolbar suits you. You'd have to
customise
> > the toolbar in some way i'd expect depending on your application, but
I'm
> > not the person to ask as I haven't tried that solution either. I think
it
> > would be nice to see some examples anyway, so I'll post my solution and
> you
> > can post one too if you like.
> >
> > Andy
> >
> > "Danny Garcia Hernandez" <danny@g2k.es> wrote in message
> > news:cuks18$cfd$1@www.eclipse.org...
> > > Hi Andy, if i can
Re: Image inside push button [message #450539 is a reply to message #450490] Tue, 15 February 2005 10:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: danny.g2k.es

Hi Stefan. Thank for share your code with us. ToolBar had been a
solutions for me, i can use image inside toolbar and this button looks
perfect with my pocket and windows mobile. The problem with toolBar and
button image is that i dont know how to control button height to avoid
exceed toolBar height.

Can i put your imageButton in flat style?.

Thanks again
Danny



Stefan Pietsch wrote:
> Hi Andy and Danny,
>
> to use a toolbar do not solve the problem, too. On PocketPC there are no
> buttons with an image!
>
> I wrote a new widget to solve the problem. Use the attached class.
>
> Bye Stefan
>
> "Andy Harrison" <andyh@agaricus.co.uk> schrieb im Newsbeitrag
> news:cupscd$8mt$1@www.eclipse.org...
>
>>yes, i think you are right, if toolbar suits you. You'd have to customise
>>the toolbar in some way i'd expect depending on your application, but I'm
>>not the person to ask as I haven't tried that solution either. I think it
>>would be nice to see some examples anyway, so I'll post my solution and
>
> you
>
>>can post one too if you like.
>>
>>Andy
>>
>>"Danny Garcia Hernandez" <danny@g2k.es> wrote in message
>>news:cuks18$cfd$1@www.eclipse.org...
>>
>>>Hi Andy, if i caný use button on pocket pc maybe toolbar can simulate my
>>>applications buttons with image.
>>>
>>>Thank
>>>Danny
>>>
>>>Andy Harrison wrote:
>>>
>>>>You can't use images inside buttons in the PocketPC. You need to use a
>>
>>label
>>
>>>>instead. I'm working on the same kind of thing at the moment. You need
>>
>>to
>>
>>>>register an event on the label for the click.
>>>>
>>>>On the subject, if anyone has a nice code snippet of a Label with an
>>
>>image,
>>
>>>>used as a button, on the pocket pc I'd like to see it. Can we have a
>>
>>nice
>>
>>>>effect for the button pressed state too please :-)
>>>>
>>>>Andy
>>>>
>>>>
>>>>"Danny Garcia Hernandez" <danny@g2k.es> wrote in message
>>>>news:cui6ij$on4$1@www.eclipse.org...
>>>>
>>>>
>>>>>Hi List.
>>>>>
>>>>>I have a simple shell with two push button. When i try to run my app
>>>>>inside PDA i can´t see the button with image inside. On PC all works
>
> ok.
>
>>>>>Here is a segment of my code.
>>>>>
>>>>>/**
>>>>>* This method initializes sShell
>>>>>*/
>>>>>private void createShell() {
>>>>>mainShell = new Shell(SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
>>>>>ImageLoader imagesResources = ImageLoader.getInstance();
>>>>>clienteButton = new Button(mainShell, SWT.NONE);
>>>>>articuloButton = new Button(mainShell, SWT.NONE);
>>>>>
>>>>>
>>>>
>>>>
> clienteButton.setImage(imagesResources.stockImages[imagesRes ources.cmdClient
>
>>>>e]);
>>>>
>>>>
>>
> articuloButton.setImage(imagesResources.stockImages[imagesRe sources.cmdArtic
>
>>>>ulo]);
>>>>
>>>>
>>>>>}
>>>>>
>>>>>Thanks Danny
>>>>
>>>>
>>>>
>>
>
>
Re: Image inside push button [message #450543 is a reply to message #450539] Tue, 15 February 2005 12:34 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 92
Registered: July 2009
Member
Thanks for the ImageButton class Stefan, just the ticket.

I've looked at both ToolBar and Stefan's ImageButton and I think that they
both have their merits. It will good to use ImageButton next to normal text
buttons on the pocket pc I'm thinking, it seems to give the same look and
feel. It's good to use the ToolBar for err... toolbars!

I'm not sure what you mean Danny about the toolbar button exceeding the
height of the toolbar. Can you make a small example?

Andy


"Danny Garcia Hernandez" <danny@g2k.es> wrote in message
news:cusk25$24b$1@www.eclipse.org...
> Hi Stefan. Thank for share your code with us. ToolBar had been a
> solutions for me, i can use image inside toolbar and this button looks
> perfect with my pocket and windows mobile. The problem with toolBar and
> button image is that i dont know how to control button height to avoid
> exceed toolBar height.
>
> Can i put your imageButton in flat style?.
>
> Thanks again
> Danny
>
>
>
> Stefan Pietsch wrote:
> > Hi Andy and Danny,
> >
> > to use a toolbar do not solve the problem, too. On PocketPC there are no
> > buttons with an image!
> >
> > I wrote a new widget to solve the problem. Use the attached class.
> >
> > Bye Stefan
> >
> > "Andy Harrison" <andyh@agaricus.co.uk> schrieb im Newsbeitrag
> > news:cupscd$8mt$1@www.eclipse.org...
> >
> >>yes, i think you are right, if toolbar suits you. You'd have to
customise
> >>the toolbar in some way i'd expect depending on your application, but
I'm
> >>not the person to ask as I haven't tried that solution either. I think
it
> >>would be nice to see some examples anyway, so I'll post my solution and
> >
> > you
> >
> >>can post one too if you like.
> >>
> >>Andy
> >>
> >>"Danny Garcia Hernandez" <danny@g2k.es> wrote in message
> >>news:cuks18$cfd$1@www.eclipse.org...
> >>
> >>>Hi Andy, if i can
Re: Image inside push button [message #450578 is a reply to message #450543] Tue, 15 February 2005 15:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: danny.g2k.es

This is a multi-part message in MIME format.
--------------020700030909030003010902
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Andy Harrison wrote:
> Thanks for the ImageButton class Stefan, just the ticket.
>
> I've looked at both ToolBar and Stefan's ImageButton and I think that they
> both have their merits. It will good to use ImageButton next to normal text
> buttons on the pocket pc I'm thinking, it seems to give the same look and
> feel. It's good to use the ToolBar for err... toolbars!
>
> I'm not sure what you mean Danny about the toolbar button exceeding the
> height of the toolbar. Can you make a small example?
>
> Andy
>
>
> "Danny Garcia Hernandez" <danny@g2k.es> wrote in message
> news:cusk25$24b$1@www.eclipse.org...
>
>>Hi Stefan. Thank for share your code with us. ToolBar had been a
>>solutions for me, i can use image inside toolbar and this button looks
>>perfect with my pocket and windows mobile. The problem with toolBar and
>> button image is that i dont know how to control button height to avoid
>>exceed toolBar height.
>>
>>Can i put your imageButton in flat style?.
>>
>>Thanks again
>>Danny
>>
>>
>>
>>Stefan Pietsch wrote:
>>
>>>Hi Andy and Danny,
>>>
>>>to use a toolbar do not solve the problem, too. On PocketPC there are no
>>>buttons with an image!
>>>
>>>I wrote a new widget to solve the problem. Use the attached class.
>>>
>>>Bye Stefan
>>>
>>>"Andy Harrison" <andyh@agaricus.co.uk> schrieb im Newsbeitrag
>>>news:cupscd$8mt$1@www.eclipse.org...
>>>
>>>
>>>>yes, i think you are right, if toolbar suits you. You'd have to
>
> customise
>
>>>>the toolbar in some way i'd expect depending on your application, but
>
> I'm
>
>>>>not the person to ask as I haven't tried that solution either. I think
>
> it
>
>>>>would be nice to see some examples anyway, so I'll post my solution and
>>>
>>>you
>>>
>>>
>>>>can post one too if you like.
>>>>
>>>>Andy
>>>>
>>>>"Danny Garcia Hernandez" <danny@g2k.es> wrote in message
>>>>news:cuks18$cfd$1@www.eclipse.org...
>>>>
>>>>
>>>>>Hi Andy, if i can
Re: Image inside push button [message #450607 is a reply to message #450539] Wed, 16 February 2005 07:42 Go to previous messageGo to next message
Stefan Pietsch is currently offline Stefan PietschFriend
Messages: 68
Registered: July 2009
Member
Hi Danny,

I did not implement flat style yet, because I do not need it. But feel free
to change my code for your requirements.

I don't no which problems I have had with toolbars, but I think there were
some.

Bye Stefan

"Danny Garcia Hernandez" <danny@g2k.es> schrieb im Newsbeitrag
news:cusk25$24b$1@www.eclipse.org...
> Hi Stefan. Thank for share your code with us. ToolBar had been a
> solutions for me, i can use image inside toolbar and this button looks
> perfect with my pocket and windows mobile. The problem with toolBar and
> button image is that i dont know how to control button height to avoid
> exceed toolBar height.
>
> Can i put your imageButton in flat style?.
>
> Thanks again
> Danny
>
>
>
> Stefan Pietsch wrote:
> > Hi Andy and Danny,
> >
> > to use a toolbar do not solve the problem, too. On PocketPC there are no
> > buttons with an image!
> >
> > I wrote a new widget to solve the problem. Use the attached class.
> >
> > Bye Stefan
> >
> > "Andy Harrison" <andyh@agaricus.co.uk> schrieb im Newsbeitrag
> > news:cupscd$8mt$1@www.eclipse.org...
> >
> >>yes, i think you are right, if toolbar suits you. You'd have to
customise
> >>the toolbar in some way i'd expect depending on your application, but
I'm
> >>not the person to ask as I haven't tried that solution either. I think
it
> >>would be nice to see some examples anyway, so I'll post my solution and
> >
> > you
> >
> >>can post one too if you like.
> >>
> >>Andy
> >>
> >>"Danny Garcia Hernandez" <danny@g2k.es> wrote in message
> >>news:cuks18$cfd$1@www.eclipse.org...
> >>
> >>>Hi Andy, if i can
Re: Image inside push button [message #451017 is a reply to message #450607] Mon, 21 February 2005 16:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: danny.g2k.es

Stefan Pietsch wrote:
> Hi Danny,
>
> I did not implement flat style yet, because I do not need it. But feel free
> to change my code for your requirements.
>
> I don't no which problems I have had with toolbars, but I think there were
> some.
>
> Bye Stefan
>
> "Danny Garcia Hernandez" <danny@g2k.es> schrieb im Newsbeitrag
> news:cusk25$24b$1@www.eclipse.org...
>
>>Hi Stefan. Thank for share your code with us. ToolBar had been a
>>solutions for me, i can use image inside toolbar and this button looks
>>perfect with my pocket and windows mobile. The problem with toolBar and
>> button image is that i dont know how to control button height to avoid
>>exceed toolBar height.
>>
>>Can i put your imageButton in flat style?.
>>
>>Thanks again
>>Danny
>>
>>
>>
>>Stefan Pietsch wrote:
>>
>>>Hi Andy and Danny,
>>>
>>>to use a toolbar do not solve the problem, too. On PocketPC there are no
>>>buttons with an image!
>>>
>>>I wrote a new widget to solve the problem. Use the attached class.
>>>
>>>Bye Stefan
>>>
>>>"Andy Harrison" <andyh@agaricus.co.uk> schrieb im Newsbeitrag
>>>news:cupscd$8mt$1@www.eclipse.org...
>>>
>>>
>>>>yes, i think you are right, if toolbar suits you. You'd have to
>
> customise
>
>>>>the toolbar in some way i'd expect depending on your application, but
>
> I'm
>
>>>>not the person to ask as I haven't tried that solution either. I think
>
> it
>
>>>>would be nice to see some examples anyway, so I'll post my solution and
>>>
>>>you
>>>
>>>
>>>>can post one too if you like.
>>>>
>>>>Andy
>>>>
>>>>"Danny Garcia Hernandez" <danny@g2k.es> wrote in message
>>>>news:cuks18$cfd$1@www.eclipse.org...
>>>>
>>>>
>>>>>Hi Andy, if i caný use button on pocket pc maybe toolbar can simulate
>
> my
>
>>>>>applications buttons with image.
>>>>>
>>>>>Thank
>>>>>Danny
>>>>>
>>>>>Andy Harrison wrote:
>>>>>
>>>>>
>>>>>>You can't use images inside buttons in the PocketPC. You need to use a
>>>>
>>>>label
>>>>
>>>>
>>>>>>instead. I'm working on the same kind of thing at the moment. You need
>>>>
>>>>to
>>>>
>>>>
>>>>>>register an event on the label for the click.
>>>>>>
>>>>>>On the subject, if anyone has a nice code snippet of a Label with an
>>>>
>>>>image,
>>>>
>>>>
>>>>>>used as a button, on the pocket pc I'd like to see it. Can we have a
>>>>
>>>>nice
>>>>
>>>>
>>>>>>effect for the button pressed state too please :-)
>>>>>>
>>>>>>Andy
>>>>>>
>>>>>>
>>>>>>"Danny Garcia Hernandez" <danny@g2k.es> wrote in message
>>>>>>news:cui6ij$on4$1@www.eclipse.org...
>>>>>>
>>>>>>
>>>>>>
>>>>>>>Hi List.
>>>>>>>
>>>>>>>I have a simple shell with two push button. When i try to run my app
>>>>>>>inside PDA i can´t see the button with image inside. On PC all works
>>>
>>>ok.
>>>
>>>
>>>>>>>Here is a segment of my code.
>>>>>>>
>>>>>>>/**
>>>>>>>* This method initializes sShell
>>>>>>>*/
>>>>>>>private void createShell() {
>>>>>>>mainShell = new Shell(SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
>>>>>>>ImageLoader imagesResources = ImageLoader.getInstance();
>>>>>>>clienteButton = new Button(mainShell, SWT.NONE);
>>>>>>>articuloButton = new Button(mainShell, SWT.NONE);
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
> clienteButton.setImage(imagesResources.stockImages[imagesRes ources.cmdClient
>
>>>>>>e]);
>>>>>>
>>>>>>
>>>>
> articuloButton.setImage(imagesResources.stockImages[imagesRe sources.cmdArtic
>
>>>>>>ulo]);
>>>>>>
>>>>>>
>>>>>>
>>>>>>>}
>>>>>>>
>>>>>>>Thanks Danny
>>>>>>
>>>>>>
>>>>>>
>>>
>
>

Hi Stefan. I have a problem using your ImageButton.java class. Maybe you
can help me. It´s a piece of my code.

ImageButton buttonBuscar = new ImageButton(cargaShell,SWT.NONE);

buttonBuscar.setLocation(25,2);
buttonBuscar.setSize(24,24);
buttonBuscar.setImage(imagesResources.stockImages[imagesReso urces.cmdBuscar]);

buttonBuscar.addSelectionListener(new SelectionListener(){

public void widgetSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
ArenaMobileBuscaCarga buscaCargaUI = new ArenaMobileBuscaCarga(new
Carga(ArenaMobileResources.dataSource));
Rectangle shellRect = buscaCargaUI.getShell().getBounds();
Rectangle displayRect = cargaShell.getDisplay().getBounds();
int x = (displayRect.width - shellRect.width) / 2;
int y = (displayRect.height - shellRect.height) / 2;
buscaCargaUI.getShell().setLocation(x, y);
buscaCargaUI.getShell().open();

while( !buscaCargaUI.getShell().isDisposed())
{
if(!Display.getDefault().readAndDispatch())
Display.getDefault().sleep();
}

I´m getting this error.

java.lang.NullPointerException
at
arenamobile.ui.ArenaMobileCargaUI$1.widgetSelected(ArenaMobi leCargaUI.java:120)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:89)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :82)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:820)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:805)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:6 13)
at arenamobile.utils.ImageButton.mouseUp(ImageButton.java:124)
at arenamobile.utils.ImageButton$2.mouseUp(ImageButton.java:38)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:136)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :82)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:2772)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2431)
at arenamobile.ui.ArenaMobileMain.main(ArenaMobileMain.java:50)

Any hints?
Thanks
Danny
Re: Image inside push button [message #451068 is a reply to message #451017] Tue, 22 February 2005 15:06 Go to previous message
Stefan Pietsch is currently offline Stefan PietschFriend
Messages: 68
Registered: July 2009
Member
Hi Danny,

I have no idea at the moment. I don't see any dependencies of the codes.
ImageButton notifies all Listeners, but you didn't use any variable of
ImageButton in widgetSelected.

I think you have to debug your method widgetSelected.

Bye Stefan

"Danny Garcia Hernandez" <danny@g2k.es> schrieb im Newsbeitrag
news:cvd1r3$eg6$1@www.eclipse.org...
> Hi Stefan. I have a problem using your ImageButton.java class. Maybe you
> can help me. It
Previous Topic:SWT slowing doing after a couple of hour
Next Topic:How to vertically center a CoolItem in a CoolBar?
Goto Forum:
  


Current Time: Fri Mar 29 07:30:49 GMT 2024

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

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

Back to the top