here is the code I use to insert my ChartPanel into my JPanel
Code: Select all
JPanel tempPanel = new JPanel();
//Clears out the JPanel
panelINhistogram.removeAll();
panelINhistogram.validate();
//Check which graph is selected.
if(CBall.isSelected())
tempPanel = kdtree.panelAll;
else if(CBmin.isSelected())
tempPanel = kdtree.panelMin;
else if (CBmax.isSelected())
tempPanel = kdtree.panelMax;
else if(CBave.isSelected())
tempPanel = kdtree.panelAve;
//Displays Histogram into JPanel with proper formatting
GroupLayout lm = (GroupLayout)panelINhistogram.getLayout();
// If GroupLayout is already set
// A GroupLayout is used by NetBeans GUI builder,
// so if you built the application in NetBeans,
// you are probably working with an
// existing GroupLayout for your JPanels
lm.setAutocreateContainerGaps(true);
lm.setAutocreateGaps(true);
GroupLayout.SequentialGroup hGroup = lm.createSequentialGroup();
hGroup.add(tempPanel);
lm.setHorizontalGroup(hGroup);
GroupLayout.SequentialGroup vGroup = lm.createSequentialGroup();
vGroup.add(tempPanel);
lm.setVerticalGroup(vGroup);
//Refreshes the JPanel
tempPanel.revalidate();
Code: Select all
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: org.jfree.chart.ChartPanel[,0,0,0x0,invalid,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=java.awt.Dimension[width=680,height=420]] is not attached to a horizontal group
at org.jdesktop.layout.GroupLayout.checkComponents(GroupLayout.java:986)
at org.jdesktop.layout.GroupLayout.prepare(GroupLayout.java:940)
at org.jdesktop.layout.GroupLayout.minimumLayoutSize(GroupLayout.java:792)
at java.awt.Container.minimumSize(Container.java:1598)
at java.awt.Container.getMinimumSize(Container.java:1583)
at javax.swing.JComponent.getMinimumSize(JComponent.java:1706)
...and so on.....