I have a method which takes a list of Tasks
. It populates the name of the Tasks
in a JCombo
with initial selection as blank.
When a user selects a Task
, another method getGraph
is called with that Task
. getGraph
returns a javax.swing.JPanel
Object
which could be added into the JFrame
. If I am successful in adding this panel into the frame, it should show a graph.
However, I do not know how to show a blank frame initially, and how to refresh the graph on the frame with the new graph in the new panel returned by JCombo ActionListener
.
The method drawGraph
is as below:
public void drawGraph(final List<MyDomain> tasks) {
// generate combo box panel
JComboBox combo = new JComboBox();
combo.addItem("");
for (MyDomain job : tasks) {
combo.addItem(task.getTaskName());
}
combo.setSelectedIndex(0);
combo.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
JComboBox jcmbType = (JComboBox) e.getSource();
String selectedTask = (String) jcmbType.getSelectedItem();
System.out.println(selectedTask);
// GraphZoomScrollPane extends javax.swing.JPanel
GraphZoomScrollPane graphPanel = getGraph(selectedTask, tasks);
// how to add this panel to the main frame and refresh it with new graph
}
});
JPanel taskNamePanel = new JPanel();
jobNamePanel.setBorder(BorderFactory.createTitledBorder("Select Task"));
jobNamePanel.add(combo);
// create a frame and add panels
JFrame frame = new JFrame("My Visual");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(taskNamePanel, BorderLayout.SOUTH);
// What will go here so that intially the frame is blank ?
frame.pack();
frame.setVisible(true);
}