• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Too many columns slowing down program

 
Gulshan Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two questions. I'll start by posting my code:


First of all, in my main loop, I'm going to have to access all of my JTextFields. I wanted to put the buildGUI function seperate from the main loop which is good programming practice, but I would have to make all of the TextFields global, which is bad programming practice. Should I leave it like it is or is there a solution to this problem?

Secondly, the program runs fine the way it is now, but if I add a few more columns its starts to lag horribly... What is causing this lag and how do I fix it?
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see a break statement for the outer loop.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally, it is impossible (or at least VERY HARD) to find where the slowdown is by looking at the code. It's almost NEVER where you think it would be. The best way to find it is to get some kind of profiler that will show you where your code is spending all it's time. Then you can focus on that part.
 
Gulshan Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the fact that the outer loop doesn't break can't be the problem. Even if I have four columns, the code in the loop where the program is spending its time is the same. If I have 8 columns, the code in the loop is still the same. So it doesn't make sense that it's getting slower when its looping through the same code in both situations... any ideas?
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say it would definitely slow down your application. Your program will constantly be executing the loop. Although it may not execute any code, it will still check, and check, and check, and check, and check... In other words, your CPU will be very very busy.
 
Gulshan Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what I'm saying is, even though it checks and checks and checks, the number of checks is going to be the same no matter how many columns there are, because its only checking for one column during the loop. I'll change it so its more efficient in general, but I'm going to guess that the problem with the columns will still apply. I'll post back when I make the changes.
 
Paul Clapham
Sheriff
Pie
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gulshan Singh wrote:I'll post back when I make the changes.


I would suggest you need a selection listener on your table, so you only do that code when the selected row changes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic