Skip to main content

background image of dialog

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
2 replies [Last post]
sriramjava86
Offline
Joined: 2010-06-15

Hi ,

I know this is very basic but still from past 8hrs i am just trying and i am not able to change the background image of the dialog programatically. My requirement is like , in my project i have many dialogs for which i am able to set the bgimage through my resource editor and its working fine. But now i have a requirement in which i need to show the dialog with a different bgimage. As its only for one dialog i thought of changing it in code programatically but was not successful. Tried all the different ways but of no luck. here are the things that i tried.

1.through code:

1. Dialog.getStyle().setBgImage(res.getImage("playbg")); - i am sure that image is available in resource file.

Dialog.getSelectedStyle().setBgImage(res.getImage("playbg"));

2. Through resource editor:

i know we can set the theme for custom components through UIID. eveywhere else its working except in dialogs.

code: Dialog myDialog = new Dialog();

myDialog.setUIID("mycustomDialog");

And in theme file i have added the following properties, but of no use. :(

mycustomDialog.setBgImage a image path.

but even this didnt work. And finally thought of creating a new resource file and adding the same to the dialog but i am not so sure whether we can do this way or not. Did anybody face this issue? Any valuable suggestions?? is there any other way of achieving this?? Please do help me

Thanks in advance

sriram

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Chen Fishbein Guest
Offline
Joined: 2010-12-07

Hi,
Try Dialog.getDialogComponent().getStyle()

Regards,
Chen

On 6/22/2011 3:13 PM, forums@java.net wrote:
> Hi ,
>
> I know this is very basic but still from past 8hrs i am just trying
> and
> i am not able to change the background image of the dialog
> programatically.
> My requirement is like , in my project i have many dialogs for which i am
> able to set the bgimage through my resource editor and its working
> fine. But
> now i have a requirement in which i need to show the dialog with a
> different
> bgimage. As its only for one dialog i thought of changing it in code
> programatically but was not successful. Tried all the different ways
> but of
> no luck. here are the things that i tried.
>
> 1.through code:
>
> 1.
> Dialog.getStyle().setBgImage(res.getImage("playbg")); - i am sure that
> image is available in resource file.
>
>
> Dialog.getSelectedStyle().setBgImage(res.getImage("playbg"));
>
> 2. Through resource editor:
>
> i know we can set the theme for custom
> components through UIID. eveywhere else its working except in dialogs.
>
> code: Dialog myDialog = new Dialog();
>
>
> myDialog.setUIID("mycustomDialog");
>
> And in theme file i have added the
> following properties, but of no use. :(
>
> mycustomDialog.setBgImage
> a image path.
>
> but even this didnt work. And finally thought of creating a
> new resource file and adding the same to the dialog but i am not so sure
> whether we can do this way or not. Did anybody face this issue? Any
> valuable
> suggestions?? is there any other way of achieving this?? Please do
> help me
>
>
>
> Thanks in advance
>
> sriram
>
>
>
>
>
>
>
>
>
>

sriramjava86
Offline
Joined: 2010-06-15

Hi Chen,

Thank you so much for your response. It worked :)

And for the people who face this kind of issue here's the solution for this: To set the bg of a dialog programaticaly u need to get the style of the Dialog as below.

Dialog myDialog = new Dialog();

myDialog.getDialogStyle().setBgImage(res.getImage("dialogbg"));

And once again thanks for posting your response chen :)