lution
lution

Reputation: 81

How to attach a JComponent to (outside) one given component's border

I want to achieve a effect that i can add JComponents to a given component's (maybe a JLable)border,like picture below

https://i.sstatic.net/3jT16.png

I try to solve it by custom a border,and the dot is draw as a image but not a component.Before works

But this time I want to turn the dot as an JComponent which can be attached to border.So,How could I achieve this?

Upvotes: 0

Views: 87

Answers (2)

camickr
camickr

Reputation: 324118

Check out Component Border.

It allows you to create a Border that contains a component. You can control the location of the component within the Border and it will manage all the insets of the border.

Upvotes: 1

sorifiend
sorifiend

Reputation: 6307

It looks like you didn't have much luck with your other question, so I suggest that this time you make a special container to manage this.

Here is an example image (not to scale):

enter image description here

First make a jPanel to store and manage everything. Then you can add a jLabel in the middle, and then add your custom jComponent inside the container in the border space.

Then just make sure everything is the right size and sits in the right position and has the correct icons, and then it will look exactly the way you want like shown in your drawing.

Edit: Note that you don't actually need to add a border to the jPanel, the image is just showing where the jComponent might sit. You will probably want to set the jPanel background to be transparent.

Upvotes: 1

Related Questions