Quellcode durchsuchen

namen in der legende

Kevin Trometer vor 8 Jahren
Ursprung
Commit
4e682d87e5
2 geänderte Dateien mit 12 neuen und 7 gelöschten Zeilen
  1. 1 0
      src/ui/view/StatisticGraph.java
  2. 11 7
      src/ui/view/StatisticGraphPanel.java

+ 1 - 0
src/ui/view/StatisticGraph.java

@@ -95,6 +95,7 @@ public class StatisticGraph extends JPanel {
 			// Calculate the Maximum
 			calcMaximum();
 			((StatisticGraphPanel)this.getParent()).setMaximumLabel(maximum);
+			((StatisticGraphPanel)this.getParent()).makeLegendPanel();
 
 			// Calculate values for each set and add them
 			addValues();

+ 11 - 7
src/ui/view/StatisticGraphPanel.java

@@ -42,6 +42,7 @@ public class StatisticGraphPanel extends JPanel {
 	private final JPanel legendPanel = new JPanel();
 	private JPanel that;
 	private Hashtable<String, StatisticGraphPanel> graphHashtable;
+	private JPanel tempP; // for makeLegend
 
 	/**
 	 * Constructor.
@@ -136,21 +137,24 @@ public class StatisticGraphPanel extends JPanel {
 	 * Make the LegendPane.
 	 */
 	public void makeLegendPanel() {
-		for (TrackedDataSet set: sGraph.objects) {
+		legendPanel.removeAll();
+		for (TrackedDataSet set : sGraph.objects) {
 			JLabel b = new JLabel(set.getCpsObject().getName());
 			b.setBackground(Color.CYAN);
 			b.setOpaque(true);
-			JPanel p = new JPanel();
-			p.add(b);
+			tempP = new JPanel();
+			tempP.add(b);
 			b.addMouseListener(new MouseAdapter() {
 				@Override
 				public void mousePressed(MouseEvent e) {
-					if (e.BUTTON3 == e.getButton())
-						legendPanel.remove(p);
-					that.updateUI();
+					if (e.BUTTON3 == e.getButton()) {
+						legendPanel.remove(tempP);
+						that.updateUI();
+					}
 				}
 			});
-			legendPanel.add(p);
+			legendPanel.add(tempP);
 		}
+		updateUI();
 	}
 }