Reputation: 11
I have created my own version of a panel so I can create some dragable tables but at the moment nothing is being added on to the panel I have created
panel class:
import javax.swing.*;
import java.awt.event.*;
import java.awt.Dimension;
import java.awt.Point;
public class Workspace extends JPanel implements MouseListener,MouseMotionListener{
private JTable t;
private DatabaseHandler d;
public Workspace(DatabaseHandler d ){
super();
this.d = d;
setPreferredSize(new Dimension(1000, 1000));
this.setLayout(null);
addMouseListener(this);
addMouseMotionListener(this);
}
public void load(String table){
t = new JTable(d.getTable(table));
//JScrollPane js=new JScrollPane(t);
this.add(t);
}
}
the code which calls it:
public class Display{
private JPanel leftPanel = new JPanel(new BorderLayout());
public JList list;
public JFrame frame;
private DatabaseHandler d = new DatabaseHandler("imdb");
private Workspace w = new Workspace(d);
public Display(){
//create the window
frame = new JFrame("FYP - Database Refactoring");
frame.getContentPane().add(w, BorderLayout.CENTER);
frame.setSize(1000,1000);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
list = new JList(d.getTableNames());
list.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e){
JList l = (JList)e.getSource();
w.load((String)l.getSelectedValue());
frame.setVisible(true);
}
});
leftPanel.add(list);
JLabel l = new JLabel("workbench");
w.add(l);
frame.getContentPane().add(leftPanel, BorderLayout.LINE_START);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
new Display();
}
}
Any help would be appricated
Upvotes: 0
Views: 30
Reputation: 324108
so I can create some dragable tables
If you need the ability to drag a JTable I would suggest that you should be using a JDesktopPane
with JInternalFrames
. You can easily drag an internal frame around the desktop. Then you just add the JTable\JScrollPane
to the internal frame like you would to a normal JFrame.
Read the section from the Swing tutorial on How to Use Internal Frames for more information and working examples.
Upvotes: 3
Reputation: 285403
Upvotes: 3