Reputation: 8898
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
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 setText
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:
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)); } } }
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?
Upvotes: 3
Views: 232
Reputation: 23629
No it appears you understand GridLayouts. The problem is elsewhere, look at other code that you might have changed, and do some profiling to determine the true source of the slowdown.
Upvotes: 3