Change height of a single button

70 views
Skip to first unread message

Trupti Dalia

unread,
Sep 28, 2013, 7:24:41 AM9/28/13
to codenameone...@googlegroups.com
 
Hello,
 
      I have created a form with couple of buttons & other components in GUI designer. In before* event of the form, I try to change the height of 2 buttons. NOTE I want to change height of just 2 specific btns and not all buttons - so setting in Theme wont be preferred. I tried :

setPreferredSize(new Dimension(300, 20));

With this, the size is set accordingly, but (1) the btn is rectangle - rounded borders are lost (2) their seems to be the original size border line around the button.
I tried

setPreferredH(20);

This makes the Width also tiny - giving a tiny square of 20*20.
Tried adding below line along with PreferredH :

setPreferredW(300);

This brings the btn on next line - size of btn must be wider than the screen size. With 250 as W, It came in same line, but the line is visible in middle in some skins of simulator.
 
Why is this difference ? Why does the border line appear on using PreferredSize() ? How to solve this ?

Shai Almog

unread,
Sep 28, 2013, 3:05:45 PM9/28/13
to codenameone...@googlegroups.com
Hi,
you should not invoke that method under normal circumstances.
To increase the button size just use padding either by customizing the button UIID in the designer tool or via getUnselectedStyle() etc.

Trupti Dalia

unread,
Sep 29, 2013, 1:29:54 AM9/29/13
to codenameone...@googlegroups.com

I don't want to increase, want to decrease the height of button. In my layout am looking for small btn rather than huge ones.
>> via getUnselectedStyle()
You mean btn.getUnselectedStyle() & then set its padding to 0 or its height or so. This way it can be modified for particular 1 button only and not all buttons of the app.
In the designer tool if I update Button UIID, then that will affect all buttons of the application and not just that particular button.
 
Did I get it right ?

Shai Almog

unread,
Sep 29, 2013, 3:03:47 AM9/29/13
to codenameone...@googlegroups.com
Partially.
If you will change Button it will affect all buttons. However you can set the UIID either via setUIID or in the GUI builder to anything e.g. "MyButton" then customize the padding of that.

The height of the buttons in most themes is constrained by their borders, the border has a minimum size implied by the graphics assigned to it (see the 9-piece image border how do I tutorial). So you would need to replace the border too in the style/uiid.
Reply all
Reply to author
Forward
0 new messages