OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Setting the size and position of a button in Java

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
jerem
Newbie
Newbie


Joined: 13 Feb 2006
Posts: 3

PostPosted: Sun Feb 19, 2006 11:07 pm    Post subject: Setting the size and position of a button in Java Reply with quote

Hello,

I want to set the position and the size of a button in a window but i don't know how to do it.
Here is how i create the button :

Code:

private void createButton() throws Exception
   {
      XControlModel buttonmodel = (XControlModel)UnoRuntime.queryInterface(
            XControlModel.class, _xMultiComponentFactory.createInstanceWithContext(
                  "com.sun.star.awt.UnoControlButtonModel",
                  _xComponentContext));
   
      XControlShape xShape = (XControlShape)UnoRuntime.queryInterface( XControlShape.class,
            _xMultiComponentFactory.createInstanceWithContext(
                  "com.sun.star.awt.UnoControlButtonModel",
                  _xComponentContext));
      
      // This code does not work
      // position and size of the shape
      // xShape.setSize( new Size( 1000, 1000  ) );
      // xShape.setPosition( new Point( 2000 , 2000  ) );
      // xShape.setControl(buttonmodel);
      
      XControl buttoncontrol = (XControl)UnoRuntime.queryInterface(
            XControl.class, _xMultiComponentFactory.createInstanceWithContext(
                  "com.sun.star.awt.UnoControlButton",
                  _xComponentContext));
      
      XPropertySet buttonprop = (XPropertySet)UnoRuntime.queryInterface(
            XPropertySet.class, buttonmodel);
      
      XButton button = (XButton)UnoRuntime.queryInterface(
            XButton.class, buttoncontrol);
      
      button.setLabel("test");
      
      buttoncontrol.setModel(buttonmodel);
      buttoncontrol.createPeer(_xToolkit, _xPeer);
      button.addActionListener(new XActionListener() {
         public void actionPerformed( ActionEvent e ) {
            System.out.println( "Hey!" );
         }

         public void disposing(com.sun.star.lang.EventObject arg0) {
            // TODO Auto-generated method stub
         }
      });
   }


Anyone know how to achieve this ?

Thank you!
Back to top
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Mon Feb 20, 2006 7:24 am    Post subject: Reply with quote

Does this Java example in SDK resolve your problem ?
<SDK>/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
jerem
Newbie
Newbie


Joined: 13 Feb 2006
Posts: 3

PostPosted: Tue Feb 21, 2006 12:36 am    Post subject: Reply with quote

SergeM wrote:
Does this Java example in SDK resolve your problem ?
<SDK>/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs


Thank you but the example use a dialog box and not a window.
It seems that a button has not the same properties in a dialog and in a window.

Because :
Code:

        Object buttonModel = xMultiServiceFactory.createInstance(
            "com.sun.star.awt.UnoControlButtonModel" );
        XPropertySet xPSetButton = ( XPropertySet )UnoRuntime.queryInterface(
            XPropertySet.class, buttonModel );
        xPSetButton.setPropertyValue( "PositionX", new Integer( 2 ) );
        xPSetButton.setPropertyValue( "PositionY", new Integer( 10 ) );
        xPSetButton.setPropertyValue( "Width", new Integer( 115 ) );
        xPSetButton.setPropertyValue( "Height", new Integer( 20 ) );
        xPSetButton.setPropertyValue( "Name", _buttonName );
        xPSetButton.setPropertyValue( "TabIndex", new Short( (short)0 ) );       
        xPSetButton.setPropertyValue( "Label", new String( "test") );

This code works in a dialog box but doesn't work in a window.

Anyone know why ?
Back to top
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Tue Feb 21, 2006 8:19 am    Post subject: Reply with quote

Sorry I didn't know there is a difference between Windows and Dialog.
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group