How to improve painting performance of DataGridView?

I recently had some slowness issues with DataGridView and the solution was the following code public static void DoubleBuffered(this DataGridView dgv, bool setting) { Type dgvType = dgv.GetType(); PropertyInfo pi = dgvType.GetProperty(“DoubleBuffered”, BindingFlags.Instance | BindingFlags.NonPublic); pi.SetValue(dgv, setting, null); } It turns double buffering on for DataGridView objects. Just call DoubleBuffered() on your DGV. Hope it … Read more

JLayeredPane and painting

As you found, a BufferedImage is an effective way to cache complex content for efficient rendering; CellTest is an example. A flyweight renderer, shown here, is another approach. Finally, I’ve re-factored your instructive example in a way that may make experimentation easier. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import … Read more

Is the Swing repaint() method still safe to use outside the EDT in Java 7+?

This is the official reference: Swing’s Threading Policy In general Swing is not thread safe. All Swing components and related classes, unless otherwise documented, must be accessed on the event dispatching thread. And the repaint method does not “document otherwise”. To doubly reassure you that you do not need to look any further than an … Read more

What’s the difference between reflow and repaint?

This posting seems to cover the reflow vs repaint performance issues http://www.stubbornella.org/content/2009/03/27/reflows-repaints-css-performance-making-your-javascript-slow/ As for definitions, from that post: A repaint occurs when changes are made to an elements skin that changes visibly, but do not affect its layout. Examples of this include outline, visibility, background, or color. According to Opera, repaint is expensive because the … Read more

javafx listview and treeview controls are not repainted correctly

Your cell factory’s updateItem(…) needs to handle the case where the cell is empty. This will be exactly the scenario when an item is removed (or becomes empty because a node in the TreeView was collapsed) and the cell that previously showed an item is reused as an empty cell: public ListCell<T> call(final ListView<T> param) … Read more

Program not accessing method paintComponent() of extended JPanel class

It’s not clear why you’re passing around byte[], but it looks like you want to update a component’s Icon with a gray thumbnail. The example below creates grayscale icons from existing sample icons and uses setIcon() to do the update. A similar approach works with any Image. See also this example that suggests ColorConvertOp, and … Read more

tech