# ResizableBorderComponent doesn't work

**URL:** <https://forum.juce.com/t/resizablebordercomponent-doesnt-work/1344>\
**Category:** General JUCE discussion\
**Created:** [January 8, 2007, 9:58am UTC](https://forum.juce.com/t/resizablebordercomponent-doesnt-work/1344 "2007-01-08T09:58:59Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jucek](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jucek](https://forum.juce.com/u/jucek)\
**Post date:** [January 8, 2007, 9:58am UTC](https://forum.juce.com/t/resizablebordercomponent-doesnt-work/1344/1 "2007-01-08T09:58:59Z")

</div>

Hi all,  
I am trying to use ResizableBorderComponent object to handle resizing of my\_Component. The problem is that the resizing doesn’t work. Actually, the breakpoints in ResizableBorderComponent::mouseDown() and .mouseDragg() etc, don’t even get hit when I click/move the mouse  
over the edge of my\_Component().

Below are the relevant pieces of my code.

.h file  
class my\_Component : public Component,  
public ComponentBoundsConstrainer  
{  
…  
private:  
ComponentDragger dragger;  
ResizableBorderComponent\* border;  
…  
}

.cpp

my\_Component::my\_Component(int x, int y, int X, int Y):  
border(0) ,borderThickness(10) // it’s pretty thick 🙂  
{

addChildComponent (border =  
new ResizableBorderComponent(this,this));  
…  
border-\>setBorderThickness (BorderSize (borderThickness));  
border-\>setBounds(this-\>getBounds());  
border-\>setVisible(true);  
…  
}

Also, there are no other components on top of the border or on my\_Component.

I would kindly appreciate any suggestions.

P.S.  
I have an equivalent code using of ResizableWindow, but I really  
need to find out why the ResizableBorderComponent doesn’t work.

:roll:

---

<div class="post-metadata">

**Author:** ![haydxn](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@haydxn](https://forum.juce.com/u/haydxn)\
**Post date:** [January 8, 2007, 11:05am UTC](https://forum.juce.com/t/resizablebordercomponent-doesnt-work/1344/2 "2007-01-08T11:05:09Z")

</div>

You’re missing the resized() function. Maybe you have it but forgot to post it here, but in case you haven’t done it:

The border needs to be set to the bounds of the container whenever it is resized. You have set it in the constructor, which is an obvious thing to try. However, without the resized function, as soon as the bounds of the component change, the bounds of the resizable border will be wrong (as they’ve not been updated).

The main reason this is broken without it is this: in the constructor of a component, the size is not yet set. You can see this in your code; you’ve created a ResizableBorderComponent, and then you’ve set its size - the constructor has been called, but you still need to set the size yourself afterwards. Thus, in yours, the constructor has been called (and your ResizableBorderComponent has been created and sized), but then - at the level which created your Component, the size is set - and the ResizableBorderComponent is not updated. You need to make sure this update happens by defining it in the Component’s ‘resized()’ function. You set its size in the same way you set it in the constructor:

```auto
my_Component::resized ()
{
   border->setBounds(this->getBounds()); 
}
```

Then hopefully all should be well.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 8, 2007, 11:09am UTC](https://forum.juce.com/t/resizablebordercomponent-doesnt-work/1344/3 "2007-01-08T11:09:37Z")

</div>

You have to resize it in your resized() method so that it’s always got the same bounds as your window. Otherwise it’ll always just stay at its original size of (0, 0) and be unclickable.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 8, 2007, 11:10am UTC](https://forum.juce.com/t/resizablebordercomponent-doesnt-work/1344/4 "2007-01-08T11:10:39Z")

</div>

ah - looks like you just beat me to it there, haydxn!

---

<div class="post-metadata">

**Author:** ![jucek](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jucek](https://forum.juce.com/u/jucek)\
**Post date:** [January 9, 2007, 3:13am UTC](https://forum.juce.com/t/resizablebordercomponent-doesnt-work/1344/5 "2007-01-09T03:13:03Z")

</div>

Thanks haydxn and jules for prompt response.

Using " border-\>setBounds(this-\>getBounds()); " is what I did originally but  
I was getting this “Unhandled exception at 0x00523c04 in myHEllo.exe: 0xC0000005: Access violation reading location 0x0000001c.” when I did it,  
so I thought I misunderstood the ResizableBorderComponent’s documentation.

The exception points to this line:  
" const bool wasResized = (compW\_ != w || compH\_ != h);"  
in Component::setBounds ()

---

<div class="post-metadata">

**Author:** ![X-Ryl669](https://avatars.discourse-cdn.com/v4/letter/x/a5b964/32.png) [@X-Ryl669](https://forum.juce.com/u/X-Ryl669)\
**Post date:** [January 9, 2007, 8:42am UTC](https://forum.juce.com/t/resizablebordercomponent-doesnt-work/1344/6 "2007-01-09T08:42:15Z")

</div>

Try “if (border) border-\>setBounds(this-\>getBounds);”, making sure you still have “My\_Component() : border(0)”.  
Whenever you get access violation, this means that you are reading/writing/executing code that is not accessible.

From the example you gave, if you are not sure your border is set (let’s say the one of the my\_Component’s base call resized()), you shouldn’t use it.

Another tip : if the Access violation location address is 0x00000000, then it’s probably because you are using a null pointer. If it is small but not zero, then you are probably using a member from a null pointer (and the virtual method are stored few bytes after the pointer).

Good luck

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 9, 2007, 11:29am UTC](https://forum.juce.com/t/resizablebordercomponent-doesnt-work/1344/7 "2007-01-09T11:29:26Z")

</div>

You don’t want to copy the border’s bounds from that of the window, though - think about it: these are local co-ordinates, not global.

---

<div class="post-metadata">

**Author:** ![haydxn](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@haydxn](https://forum.juce.com/u/haydxn)\
**Post date:** [January 9, 2007, 12:27pm UTC](https://forum.juce.com/t/resizablebordercomponent-doesnt-work/1344/8 "2007-01-09T12:27:26Z")

</div>

crumbs, yes, i was being lazy on my answer. personally i always do it like this:

resizer-\>setBounds (0,0,getWidth(),getHeight());

I just couldn’t be bothered typing it and was switched off! 🙂

---

<div class="post-metadata">

**Author:** ![jucek](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jucek](https://forum.juce.com/u/jucek)\
**Post date:** [January 9, 2007, 11:56pm UTC](https://forum.juce.com/t/resizablebordercomponent-doesnt-work/1344/9 "2007-01-09T23:56:40Z")

</div>

Thanks for you help guys 🙂

“border-\>setBounds (0,0,getWidth(),getHeight());” does the job, but  
now when I start dragging the horizontal borders (i.e. top or bottom) the window expands all the way to the edge of it’s parent and the edge being dragged disappears completely. When I try to drag the vertical borders (i.e. left or right edge), the entire window just disappears.

Now, all that my my\_Component’s constructor does is this:  
“my\_Component::my\_Component (int x, int y, int X, int Y)  
: Component (T(“jaSelfContainer”)) ,  
,border(0)  
,borderThickness(10)  
{   
setBounds(x, y, X, Y);  
addChildComponent (border=new ResizableBorderComponent (this, this));  
border-\>setBounds(0,0,getWidth(),getHeight());   
border-\>setBorderThickness (BorderSize (borderThickness));   
border-\>setVisible(1);  
}”

… and the only thing that both resize() and moved() do is :  
"if (border) border-\>setBounds (0,0,getWidth(),getHeight()); "

---

<div class="post-metadata">

**Author:** ![jucek](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jucek](https://forum.juce.com/u/jucek)\
**Post date:** [January 12, 2007, 8:28pm UTC](https://forum.juce.com/t/resizablebordercomponent-doesnt-work/1344/10 "2007-01-12T20:28:59Z")

</div>

Hi,  
I am just wondering what happened.  
I suppose my issue was caused by some obvious mistake on my part and you just gave up on it or maybe it’s so hard that more time is needed to address it.

In either case, I am still interested if anybody has any suggestions  
and I greatly appreciate your help so far . Thanks 🙂

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 8:58pm UTC](https://forum.juce.com/t/resizablebordercomponent-doesnt-work/1344/11 "2017-05-12T20:58:23Z")

</div>

Closed on May 12, 2017, 8:58pm UTC


