| View previous topic :: View next topic |
| Author |
Message |
jerem Newbie

Joined: 13 Feb 2006 Posts: 3
|
Posted: Sun Feb 19, 2006 11:07 pm Post subject: Setting the size and position of a button in Java |
|
|
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 |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
jerem Newbie

Joined: 13 Feb 2006 Posts: 3
|
Posted: Tue Feb 21, 2006 12:36 am Post subject: |
|
|
| 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 |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
|