user6296840
user6296840

Reputation:

java swing GUI. Allow user to rearrange buttons

Many programs allow to freely rearrange buttons on gui. For instance Firefox and Chrome have "customize" option. How to do it in Java? Sure, I can bring GUI constrains to settings file and let user edit it, but this isn't user friendly. Is there a better way to do this?

Upvotes: 0

Views: 212

Answers (2)

Keshav Pandey
Keshav Pandey

Reputation: 73

You can try creating a preference menu like you find in Chrome etc. This will provide for a familiar and user friendly method to do so. You can also go ahead and allow the use to change icon or size if you want to.

Another way could be that you allow the buttons to be dragable and resizable across a container and using events based on movements of the mouse to reorder the buttons in question.

Upvotes: 2

camickr
camickr

Reputation: 324118

How to do it in Java?

There is no built in support, so you need to provide this yourself.

  1. You might start with a configuration dialog. It could display a JList with the text of all the buttons in the order in which you want the buttons displayed.
  2. Then the user would be able to drag each item in the list to a new location
  3. When the user is finished they would click "Save" and you would store the order in a user properties file.
  4. Then you would iterate through the list and change the order of each button on your panel.
  5. Every time you start your application you would need to read the user properties file and perform step 4.

Check out the Drop Demo Project from the Swing tutorial on Drag and Drop. It will show you how to implement the JList so items can be dragged to a new location.

So basically you need to write the code yourself.

Upvotes: 3

Related Questions