Reputation: 35
I have this code in which a Gantt Chart will be shown on another JFrame
, other than the main UI frame. Is there any way such that the drawn Graphics here will be shown on a JPanel
on the main UI frame?
chart= new JFrame();
final ArrayList<Task> tasks = taskList;
final int ET = processET;
chart.setSize(300, 300);
chart.setContentPane(new JPanel(){
public void paint(Graphics g){
for(int j=0;j < tasks.size();j++)
{
int ST = 0;
if(j!= tasks.size()-1) ST = tasks.get(j + 1).getStartTime();
else ST = ET;
int Product = ST * 20;
g.drawRect(50,50,Product,30);
g.drawString("p"+tasks.get(j).getPID(),(55+(tasks.get(j).getStartTime()*20)),70);
g.drawString(""+tasks.get(j).getStartTime(), (50+(tasks.get(j).getStartTime()*20)),100);
}
g.drawString(""+ET,50+(ET*20),100);
}
});
chart.pack();
chart.setLocationRelativeTo(null);
chart.setVisible(true);
I tried this code so that it would put it on a JPanel, but obviously it did not work, hence this inquiry. Please help and thanks :)
panel_2 = new JPanel(){ "same thing" };
panel.add(panel_2);
Upvotes: 0
Views: 483
Reputation: 168825
Is there any way such that the drawn Graphics here will be shown on a JPanel on the main UI frame?
There are a number of ways. See this answer for details. I'm thinking either a CardLayout
or JTabbedPane
might be the easiest, given that code is already rendered in a JPanel
(that is currently added to a frame for display).
Upvotes: 2