Hi Steve,

It worked! Thank you!

Best regards,

David

On Wednesday, March 29, 2017 at 3:03:18 PM UTC-3, Steve Hannah wrote:
>
> First ensure that the button's action is actually being fired.  (Add some 
> debugging code System.out.println("here") inside the action listener and 
> make sure it runs).
>
> The other thing to check is if container1 will have bounds.
>
> Perhaps my original suggestion of a border layout has thrown you off track 
> here.  Perhaps it is better just to implement the calcPreferredSize() 
> method in the custom component (which you should do anyways) to give it 
> some preferred bounds that are big enough to see - so that the bounds don't 
> go to zero.
>
> Steve
>
> On Tue, Mar 28, 2017 at 11:48 AM, David <[email protected] <javascript:>
> > wrote:
>
>> Hi Steve,
>>
>> I set Container1 to border layout and add the following code for a button 
>> action:
>>
>> findContainer1(c.getComponentForm()).add(BorderLayout.CENTER, new 
>> Component() {
>> @Override
>> public void paint(Graphics g) {
>> g.setColor(0xff0000);
>> g.fillRect(getX(), getY(), getWidth(), getHeight());
>> }
>>
>> });
>> c.getComponentForm().revalidate();
>>
>>
>> When I click the button nothing happens. What am I doing wrong?
>>
>> Thank you for your help,
>>
>> David
>>
>> On Tuesday, March 28, 2017 at 1:43:54 PM UTC-3, Steve Hannah wrote:
>>>
>>> I wouldn't override Label.  Rather just override Component since you're 
>>> going to be doing custom drawing anyways -- you don't need the default 
>>> rendering of Label. 
>>>
>>> Since this is your first custom component, you should start simple.  
>>> Just draw a rectangle and then test.  When you get that working and you're 
>>> comfortable with how the coordinates work, then you can draw an image.
>>>
>>> You should override calcPreferredSize() to return a sensible default 
>>> size for the component also, or it may shrink down to nothing in some 
>>> layouts because the layout manager doesn't know that your component needs 
>>> any space.  For testing purposes I often just place my component in the 
>>> center of a border layout so that I don't have to worry about sizing yet.
>>>
>>> Steve
>>>
>>> On Tue, Mar 28, 2017 at 7:44 AM, David <[email protected]> wrote:
>>>
>>>> Hi Steve,
>>>>
>>>> I'm trying to use drawImage() method of Graphics class. I have inserted 
>>>> a new label on the form, using the Codename One Designer and I should 
>>>> override the paint method of the label to draw the image on it, right? I'm 
>>>> having trouble doing that, could you please give me a hint?
>>>>
>>>> Best regards,
>>>>
>>>> David
>>>>
>>>>
>>>> On Tuesday, March 21, 2017 at 6:15:56 PM UTC-3, Steve Hannah wrote:
>>>>>
>>>>> Those examples were just to show you 2D drawing on a graphics 
>>>>> context.  Graphics includes a few drawImage() methods that allow you to 
>>>>> draw images.  You would use those to draw your images.
>>>>>
>>>>> Steve
>>>>>
>>>>> On Tue, Mar 21, 2017 at 2:10 PM, David <[email protected]> wrote:
>>>>>
>>>>>> Hi Steve,
>>>>>>
>>>>>> I have checked the clock demo, but the speedometer image I would like 
>>>>>> to use is a very complex image made in photoshop (with effects, shadows, 
>>>>>> etc).
>>>>>> I think it will be very hard to draw the same image using Graphics 
>>>>>> method.
>>>>>> Is it possible to import an image from a library using Graphics 
>>>>>> method and then rotate and position it?
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> David
>>>>>>
>>>>>> On Tuesday, March 21, 2017 at 5:56:44 PM UTC-3, Steve Hannah wrote:
>>>>>>>
>>>>>>> I would be tempted to do this in a single component, overriding the 
>>>>>>> paint(Graphics) method, and drawing both images directly on Graphics 
>>>>>>> context.  This would give you full control over placement, rotation, 
>>>>>>> sizing, etc..., of images.
>>>>>>>
>>>>>>> Check out the clock demo for an example that is similar:
>>>>>>> https://www.codenameone.com/demos-ClockDemo.html
>>>>>>>
>>>>>>> The circle progress library might also give you some ideas:
>>>>>>>
>>>>>>> https://github.com/chen-fishbein/CN1CircleProgress/blob/master/CN1CircleProgress/src/com/codename1/progress/CircleFilledProgress.java
>>>>>>>  
>>>>>>> <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fchen-fishbein%2FCN1CircleProgress%2Fblob%2Fmaster%2FCN1CircleProgress%2Fsrc%2Fcom%2Fcodename1%2Fprogress%2FCircleFilledProgress.java&sa=D&sntz=1&usg=AFQjCNHagabFhcLOhtcrUuvMmqhqBc31Qw>
>>>>>>>
>>>>>>> Steve
>>>>>>>
>>>>>>>
>>>>>>> On Tue, Mar 21, 2017 at 1:30 PM, David <[email protected]> wrote:
>>>>>>>
>>>>>>>> Hi Steve,
>>>>>>>>
>>>>>>>> Thanks for the answer.
>>>>>>>> Basically, I want to build a speedometer using 2 images (meter 
>>>>>>>> image and pointer image). So I used Layered Layout with the pointer 
>>>>>>>> image 
>>>>>>>> in front of the meter image.
>>>>>>>> Since the meter is a half circle type, I have to move the pointer 
>>>>>>>> image to the right position and then I can rotate the pointer image to 
>>>>>>>> indicate speed.
>>>>>>>> I was able to move the pointer image to the right place by changing 
>>>>>>>> Padding/Margin or by increasing the height of the pointer image 
>>>>>>>> (adding a 
>>>>>>>> transparent image below it), but the "blank space" below the 
>>>>>>>> speedometer 
>>>>>>>> increased and other components below it didn't fit the screen. 
>>>>>>>>
>>>>>>>> Answers to your questions:
>>>>>>>> 1) Other components shouldn't move
>>>>>>>> 2) It will be permanent, except the rotation of the pointer
>>>>>>>> 3) I would like to animate the pointer movement.
>>>>>>>>
>>>>>>>> Thanks and regards,
>>>>>>>>
>>>>>>>> David
>>>>>>>>
>>>>>>>>
>>>>>>>> On Monday, March 20, 2017 at 5:21:43 PM UTC-3, Steve Hannah wrote:
>>>>>>>>>
>>>>>>>>> It is the job of the layout manager to set size/position of 
>>>>>>>>> components.  If you explicitly set the x, y, width, height, of a 
>>>>>>>>> component, 
>>>>>>>>> your changes will be "wiped out" the next time any of the component's 
>>>>>>>>> parents are revalidated/laid out again.
>>>>>>>>>
>>>>>>>>> You can set the preferredSize (`setPreferredH()`, 
>>>>>>>>> `setPreferredW()`), but these methods are marked deprecated to 
>>>>>>>>> discourage 
>>>>>>>>> use as it is better to use a layout manager for this sort of thing.
>>>>>>>>>
>>>>>>>>> If you can describe a little bit more about what you are trying to 
>>>>>>>>> do, then I might be able to offer more specific advice.  Things to 
>>>>>>>>> think 
>>>>>>>>> about:
>>>>>>>>>
>>>>>>>>> 1. What will happen to the other components in the form when you 
>>>>>>>>> resize and reposition the component?  Do they get moved or shifted at 
>>>>>>>>> all?
>>>>>>>>> 2. Is this a new "permanent" state for the form, or is this just a 
>>>>>>>>> temporary "highlight" that will be soon removed?
>>>>>>>>> 3. Do you want to animate the component on the size change, or 
>>>>>>>>> just "jump" to a new position?
>>>>>>>>>
>>>>>>>>> Steve
>>>>>>>>>
>>>>>>>>> On Mon, Mar 20, 2017 at 5:55 AM, David <[email protected]> 
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I would like to change position of a component dynamically (when 
>>>>>>>>>> a button is pressed or after a period of time).
>>>>>>>>>> I tried to use setWidth/height/x/y, but every time the screen is 
>>>>>>>>>> touched or rotated, the components goes back to its original 
>>>>>>>>>> position 
>>>>>>>>>> (defined on the layout manager).
>>>>>>>>>>
>>>>>>>>>> Is it possible to change a component position different to the 
>>>>>>>>>> position set on layout manager?
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>>
>>>>>>>>>> David
>>>>>>>>>>
>>>>>>>>>> -- 
>>>>>>>>>> You received this message because you are subscribed to the 
>>>>>>>>>> Google Groups "CodenameOne Discussions" group.
>>>>>>>>>> To unsubscribe from this group and stop receiving emails from it, 
>>>>>>>>>> send an email to 
>>>>>>>>>> [email protected].
>>>>>>>>>> Visit this group at 
>>>>>>>>>> https://groups.google.com/group/codenameone-discussions.
>>>>>>>>>> To view this discussion on the web visit 
>>>>>>>>>> https://groups.google.com/d/msgid/codenameone-discussions/bdc3f6bc-09c4-4239-ac78-c862a4a72daa%40googlegroups.com
>>>>>>>>>>  
>>>>>>>>>> <https://groups.google.com/d/msgid/codenameone-discussions/bdc3f6bc-09c4-4239-ac78-c862a4a72daa%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>>>>> .
>>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> -- 
>>>>>>>>> Steve Hannah
>>>>>>>>> Software Developer
>>>>>>>>> Codename One
>>>>>>>>> http://www.codenameone.com
>>>>>>>>>
>>>>>>>> -- 
>>>>>>>> You received this message because you are subscribed to the Google 
>>>>>>>> Groups "CodenameOne Discussions" group.
>>>>>>>> To unsubscribe from this group and stop receiving emails from it, 
>>>>>>>> send an email to 
>>>>>>>> [email protected].
>>>>>>>> Visit this group at 
>>>>>>>> https://groups.google.com/group/codenameone-discussions.
>>>>>>>> To view this discussion on the web visit 
>>>>>>>> https://groups.google.com/d/msgid/codenameone-discussions/d622fbbf-e31f-46c8-8d93-1c8bca71a985%40googlegroups.com
>>>>>>>>  
>>>>>>>> <https://groups.google.com/d/msgid/codenameone-discussions/d622fbbf-e31f-46c8-8d93-1c8bca71a985%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>>> .
>>>>>>>>
>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> -- 
>>>>>>> Steve Hannah
>>>>>>> Software Developer
>>>>>>> Codename One
>>>>>>> http://www.codenameone.com
>>>>>>>
>>>>>> -- 
>>>>>> You received this message because you are subscribed to the Google 
>>>>>> Groups "CodenameOne Discussions" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, 
>>>>>> send an email to [email protected]
>>>>>> .
>>>>>> Visit this group at 
>>>>>> https://groups.google.com/group/codenameone-discussions.
>>>>>> To view this discussion on the web visit 
>>>>>> https://groups.google.com/d/msgid/codenameone-discussions/f917d26b-243c-40da-92fd-5860b90f5c8d%40googlegroups.com
>>>>>>  
>>>>>> <https://groups.google.com/d/msgid/codenameone-discussions/f917d26b-243c-40da-92fd-5860b90f5c8d%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>>
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> -- 
>>>>> Steve Hannah
>>>>> Software Developer
>>>>> Codename One
>>>>> http://www.codenameone.com
>>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "CodenameOne Discussions" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>> Visit this group at 
>>>> https://groups.google.com/group/codenameone-discussions.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/codenameone-discussions/c14b15cb-09e5-44a9-b4b2-b89f70ae4b01%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/codenameone-discussions/c14b15cb-09e5-44a9-b4b2-b89f70ae4b01%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>>
>>> -- 
>>> Steve Hannah
>>> Software Developer
>>> Codename One
>>> http://www.codenameone.com
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "CodenameOne Discussions" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] 
>> <javascript:>.
>> Visit this group at 
>> https://groups.google.com/group/codenameone-discussions.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/codenameone-discussions/816c1ff5-4e89-43aa-add1-e4eb5be3a0f7%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/codenameone-discussions/816c1ff5-4e89-43aa-add1-e4eb5be3a0f7%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Steve Hannah
> Software Developer
> Codename One
> http://www.codenameone.com
>

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/c56eae8c-0caf-4b1c-9f52-428a2fcbb49a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to