Note that there are some explanatory texts on larger screens.

plurals
  1. POMinor Refactoring in Java Swing application causes huge slowdown
    text
    copied!<p>I've been tasked with doing refactoring to a Java Swing application we have here that's pretty crufty. My job is to clean up the code and make it more dynamic as we're going to start using it with a second project and it needs to be able to adjust appropriately. There is a small portion of one window that contains</p> <ul> <li>A button</li> <li>A JFormattedTextField that is used to select dates.</li> <li>A 3X4 table of JLabels that display data.</li> </ul> <p>The person who originally wrote this simply used a GridBagLayout JPanel and then hardcoded everything, including the table's header and row label's and left empty JLabel's in the dynamic data position. When the dynamic information is received <code>setText</code> is called with the text data. Part of my refactoring will cause the entire table to be dynamic in dimension as well as content so I decided to make the table a sub-panel with a GridLayout and dynamically set the contents and dimensions with this piece of code:</p> <pre> public void updateInfoPanel(ArrayList rows) { System.out.println("Updating Info Panel!"); //genericInfo is the new sub panel in question. genericInfo.removeAll(); GridLayout layout = new GridLayout(); layout.setColumns(rows.get(0).length); layout.setRows(rows.size()); genericInfo.setLayout(layout); for(String[] row : rows) { for(String element : row) { genericInfo.add(new Label(element)); } } } </pre> <p>I have verified that this is only ever getting called one time per window creation but the entire window is now incredibly sluggish. It can take >5 seconds to respond to clicks in other parts of the frame that used to respond in fractions of a second. Does anyone know what would cause this? Is there something about GridLayouts that I don't understand? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload