-2

Image Example

i want to create a Database designer so i might also need a way to have UI for making relationship between two tables. Tool : JAVA swing

Asdakamessoy
  • 87
  • 4
  • 12

1 Answers1

0

The short answer to your question is, no. There are no ready made components. You're going to have to roll up your selves and get your hands dirty.

Break your problem down.

You need the entity to be floatable. The only two (decent) choices you have are JLayeredPane and JDesktopPane. Which you choice will depend on the features you want to implement. I'd probably start with JLayeredPane. This will allow you to position components where you want them and also provides the ability to more easily control the Z-level.

The problem with this, is you will become responsible for not only positioning the components, but also resizing them.

Next, you need an entity component.

This would be, to my mind, a series of compound components. You'd need a "header" or "title" component, which would provide the name of the table, the expand control and a means by which you can drag it.

I'd start with a simple JPanel. Onto which I would add a JLabel, a JTextField and either a JButton or JLabel to act as the expand control, depending on what look I was after.

The JLabel will act as the title for the header. The JTextField would as as the editor. Start by making the text field hidden. With a little bit of clever use of a layout manager, you can place two components in the space place. When the text field is made visible, it will be able to lay over the label.

You will need to add a mouse listener and mouse motion listener this component. When clicked, the editor should be shown. Use an ActionListener and FocusListener to determine when the user has finished editing and update the label and hide the editor. You'll probably also want to bind a Esc to the field to allow the user to cancel the edit, key bindings are best for this.

You will also need to track the mouse drag events so you can reposition the "entity"

This header component would then be added to the entity component.

You would need either a JList or JTable to hold the field information. To my mind, a JTable would provide the most functionality, allowing you to more easily edit the field information.

You will also need to perform some custom painting to provide links from one table to another. This is a non-trival problem and is going to need some seriously good design on your part.

Every thing you need to get started can be found at Creating a GUI With JFC/Swing, but you're also going to need to read through and understand Performing Custom Painting and 2D Graphics

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • have you ever done this thing before ?? can i have a code Example ?? – Asdakamessoy Mar 30 '13 at 16:40
  • Have you ever used Swing before? You stand there and abuse me, then ask for an example? – MadProgrammer Mar 30 '13 at 19:41
  • im not abusing , i m just asking ! because i need an example to see how that can work .. sorry you took my wordings in a wrong sense :S – Asdakamessoy Mar 30 '13 at 20:27
  • i was just asking you for one coded example .. if you have worked on something like this.. i never meant to offend you. yes im using swing for the 1st time in my project i would be very thankful if you help me out :) – Asdakamessoy Mar 30 '13 at 20:31
  • Appologies for been tetchy, taking care of my 10 month old while my is sick, haven't slept in 6 days. Read through the links and try something, when you have a problem post a question. People will reward effort – MadProgrammer Mar 30 '13 at 20:57
  • thankyou soo much i will read through the links :) takecare p.s. hope you get well soon :) – Asdakamessoy Mar 30 '13 at 21:03