initial label width bug might be fixed at last
authoramwaterhouse <Andrew Waterhouse>
Tue, 15 Mar 2005 16:33:36 +0000 (16:33 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 15 Mar 2005 16:33:36 +0000 (16:33 +0000)
src/jalview/gui/AlignmentPanel.java

index 15f1a1f..296bb80 100755 (executable)
@@ -38,6 +38,24 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene
     secondaryPanelHolder.add(ssPanel, BorderLayout.CENTER);\r
     idPanelHolder.add(idPanel, BorderLayout.CENTER);\r
     idPanel.addNotify();\r
+\r
+    javax.swing.JFrame f = new javax.swing.JFrame();\r
+    f.addNotify();\r
+    FontMetrics fm = f.getGraphics().getFontMetrics(av.font);\r
+    AlignmentI al = av.getAlignment();\r
+\r
+    int i   = 0;\r
+    int idWidth = 0;\r
+    while (i < al.getHeight() && al.getSequenceAt(i) != null)\r
+    {\r
+      SequenceI s   = al.getSequenceAt(i);\r
+      String str   = s.getDisplayId();\r
+      if (fm.stringWidth(str) > idWidth)\r
+        idWidth = fm.stringWidth(str);\r
+      i++;\r
+    }\r
+    hscrollFillerPanel.setPreferredSize(new Dimension(idWidth, 12));\r
+\r
     scalePanelHolder.add(scalePanel, BorderLayout.CENTER);\r
     scorePanelHolder.add(scorePanel, BorderLayout.CENTER);\r
     seqPanelHolder.add(seqPanel, BorderLayout.CENTER);\r
@@ -179,16 +197,11 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene
 \r
   public void RefreshPanels()\r
   {\r
-    javax.swing.SwingUtilities.invokeLater(new Runnable()\r
-          {\r
-            public void run()\r
-            {\r
-\r
               requestFocus();\r
               invalidate();\r
               idPanelHolder.setPreferredSize(idPanel.idCanvas.getPreferredSize());\r
-              hscrollFillerPanel.setPreferredSize(new Dimension(idPanel.idCanvas.\r
-                  getPreferredSize().width, 12));\r
+              if(idPanel.idCanvas.getPreferredSize()!=null)\r
+                hscrollFillerPanel.setPreferredSize(new Dimension(idPanel.idCanvas.getPreferredSize().width, 12));\r
               idSpaceFillerPanel1.setPreferredSize(new Dimension(500,\r
                   av.charHeight / 2 + 12));\r
               scalePanelHolder.setPreferredSize(new Dimension(500,\r
@@ -209,9 +222,6 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene
               if (overviewPanel != null)\r
                 overviewPanel.updateOverviewImage();\r
 \r
-            }\r
-          });\r
-\r
           validate();\r
           repaint();\r
   }\r