• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create resizable swing components as in Netbeans Swings (GUI), drag and drop?  RSS feed

 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi every one,

How to create resizable swing components as in Netbeans Swings (GUI), drag and drop?

I have a requirement where in i have to create resizable swing components (JTextfield, JLabel....) with drag and drop functionality...
Also i need to set some custom properties to each component.....(through JPopupMenu)

need help
thanks
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply.........

i tried and succeeded.........but failed to get the scrollbar in the panel.
how to display the scrollbar when a component is dragged beyond the panel dimensions?

 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scrollbars appear automatically when the "preferred size" of the component added to the scrollpane is greater than the "size" of the scrollpane.

So, if you are dragging components around a panel you need to dynamically recalculate the preferred size of the panel every time you move a component.
 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to dynamically recalculate the preferred size of the panel every time you move a component ?

I have added the ComponentListener to the dragged component and set the preferred size, but nothing happened

Note:
actually i dont know how to calculate the preferred size, instead i have harcoded the values for verification......but nothing happened..
 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply...
Note: Here the panel layout is set to null
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have added the ComponentListener to the dragged component and set the preferred size, but nothing happened


You need to set the preferred size of the panel, which means you need to loop through "all" the components on the panel to find the greatest x/y values because they could belong to different components.
 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply.......

iam facing the following problems...

1.Unable to get the scrollbar when the component is created at the borders of the panel........but, upon dragging the component scrollbar is displayed.

2.How to display scrollbar, when components are moved towards South and West directions? (or) how to stop moving the components, when they reaches South and West borders?
Note: Succeeded in displaying the scrollbar, when components are moved towards East and South directions


 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!