Skip to content

Commit

Permalink
Retain last component in rendererPane. Testcase added
Browse files Browse the repository at this point in the history
  • Loading branch information
prsadhuk committed Jan 24, 2024
1 parent 301ecbc commit de37cc9
Showing 1 changed file with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/*
* @test
* @bug 6507038
* @summary Verifies memory leak in BasicTreeUI TreeCellRenderer
* @summary Verifies memory leak in BasicTreeUI TreeCellRenderer
* @run main TreeCellRendererLeakTest
*/

Expand All @@ -42,35 +42,34 @@
import javax.swing.tree.TreeNode;

public class TreeCellRendererLeakTest {

static long smCount = 0;
static boolean done;
static boolean done;

private static JFrame frame;
private JPanel jPanel1;
private JPanel jPanel2;
private JScrollPane jScrollPane1;
private JTabbedPane jTabbedPane1;
private JTree jTree1;
// End of variables declaration


// JLabel with an instance counter
public class TestLabel extends JLabel {
public TestLabel() {
smCount++;
}

public void finalize( ) {
smCount--;
}
}

// Custom TreeCellRenderer
public class TreeCellRenderer extends DefaultTreeCellRenderer {

public TreeCellRenderer( ) {
}

// Create a new JLabel every time
public Component getTreeCellRendererComponent(
JTree tree,
Expand All @@ -87,11 +86,11 @@ public Component getTreeCellRendererComponent(
} else {
label.setBackground(getBackgroundNonSelectionColor());
}

return label;
}
}

public TreeCellRendererLeakTest() {
initComponents();
jTree1.setCellRenderer(new TreeCellRenderer());
Expand All @@ -110,7 +109,7 @@ public void run( ) {
infoThread.setDaemon(true);
infoThread.start();
}

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jTabbedPane1 = new javax.swing.JTabbedPane();
Expand Down Expand Up @@ -140,7 +139,7 @@ private void initComponents() {
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}// </editor-fold>

public static void main(String args[]) throws Exception {
try {
SwingUtilities.invokeAndWait(() -> {
Expand All @@ -155,9 +154,9 @@ public static void main(String args[]) throws Exception {
frame.dispose();
}
});
}
}
}

// Periodically cause a nodeChanged() for one of the nodes
public void runChanges() {
long count = 0;
Expand Down Expand Up @@ -185,7 +184,7 @@ public void run( ) {
}
done = true;
}

// Print number of uncollected TestLabels
public void runInfo( ) {
long time = System.currentTimeMillis();
Expand All @@ -203,5 +202,5 @@ public void runInfo( ) {
throw new RuntimeException("TreeCellRenderer component leaked");
}
}

}

0 comments on commit de37cc9

Please sign in to comment.