• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to reduce jlabel with selection border around it at run time  RSS feed

 
sam onikosi
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a project (assignment) and i want to be able to click on jlabel and the select border will show (as shown in the image attached) and i used it to resize the jlabel.

i tried

@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
setPreferredSize(getSize());
}
});`

yet is not working.
i tried some other code that are not working
5..jpg
[Thumbnail for 5..jpg]
 
Tony Docherty
Bartender
Posts: 3205
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

There isn't enough information in your post to allow us to determine what is happening in your code, please TellTheDetails. Saying "and I tried some other code that are not working" really doesn't help us to help you but providing an SSCCE so we can see exactly what is happening would be really useful.
 
sam onikosi
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Tony
I am a newbie
i dont know how to go about it so i need assistant

for the code i tried they are just try and error so i dont want to be posting junks

what i am try to do is for a jlabel to be selected like that anytime i clicked on it at runtime
 
Tony Docherty
Bartender
Posts: 3205
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sam,

Don't worry we will try to help you but we can't help if we have no idea what you are doing. You need to provide a good explanation of what you are trying to do and what your code is actually. You also need to provide enough code that we can see where the error is.
An SSCCE would help greatly as we can run the code (if you don't know what one is click on SSCCE and it will take you to a page that will explain it to you).

If I were to guess at what is wrong I would say the componentResized method is not being called as you aren't using a layout manager or you are using a layout manager and it is overriding your changes or your code for tracking the mouse resize action isn't setting the size correctly or .... and I could go on all day guessing at what the cause is might be but that isn't going to help you much.

At the very least you should be putting a print statement in the componentResized method to print out the event details and the new size.
 
sam onikosi
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all,

Maybe i suppose to start with a question that is it possible at runtime to select a jlabel and it will have selected border (the 8 adjustment dot around the image i attached)
because in my few weeks in java i have not seen such.
 
Tony Docherty
Bartender
Posts: 3205
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not a standard feature of any Swing component. I assumed you had written the code to display the border and make it selectable.
 
sam onikosi
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Tony
I made an application and i used netbeans swing(the drag and drop), and it is very long if im to add the code
do you mind if i attach the project's folder then you download and run it and help me because i am stuck for 2 days now(dont know if its allow here).

What i wants is i have 3Jlabels at the runtime when you click on any of it its created a similar Jlabel inside a Jpanel. (I did that)

now when i wanted to the resize the created JLabel using a button the code give me error. (NullPointerException)

here is the code that i used to creates the Jlabel(child) when parent is clicked



AND FOR THE BUTTON I USED


although i have image in each Jlabel but if i can be able to apply the same effected
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!