1 19 20 package org.netbeans.modules.junit; 21 22 import java.awt.Dimension ; 23 import javax.swing.JPanel ; 24 import javax.swing.SwingUtilities ; 25 26 45 public class SelfResizingPanel extends JPanel { 46 47 51 private boolean painted = false; 52 53 54 public SelfResizingPanel() { 55 super(); 56 } 57 58 72 protected void paintChildren(java.awt.Graphics g) { 73 74 83 84 super.paintChildren(g); 85 if (!painted) { 86 paintedFirstTime(g); 87 painted = true; 88 } 89 } 90 91 97 protected void paintedFirstTime(java.awt.Graphics g) { 98 SwingUtilities.invokeLater(new Runnable () { 99 public void run() { 100 adjustWindowSize(); 101 } 102 }); 103 } 104 105 112 protected void adjustWindowSize() { 113 Dimension currSize = getSize(); 114 int currHeight = currSize.height; 115 int prefHeight = getPreferredSize().height; 116 if (currHeight < prefHeight) { 117 int delta = prefHeight - currHeight; 118 java.awt.Window win = SwingUtilities.getWindowAncestor(this); 119 Dimension winSize = win.getSize(); 120 win.setSize(winSize.width, winSize.height + delta); 121 } 122 } 123 124 132 protected boolean isPainted() { 133 return painted; 134 } 135 136 } 137 | Popular Tags |