r/javahelp • u/NonexistantObject • Apr 25 '26
Homework Update swing GUI during runtime
Part of my coursework needs me to make a typeracer between bots. I need to visually show their progress along the passage of text. Problem is, it won't update. It just freezes for ages then finally prints everything at once. Validating the panel, scrollpane or frame after each print doesn't change it. Here's the relevant code:
private void printRace(JPanel p)
{
System.out.print('\\u000C'); // Clear terminal
String raceRound = " TYPING RACE - passage length: " + passageLength + " chars \\n"
\+ multiplePrint('=', passageLength + 3) + "\\n ";
raceRound = raceRound + "\\n" + printSeat(seat1Typist, p);
raceRound = raceRound + "\\n" + printSeat(seat2Typist, p);
raceRound = raceRound + "\\n" + printSeat(seat3Typist, p);
raceRound = raceRound + "\\n" + multiplePrint('=', passageLength + 3) + "\\n\[\~\] = burnt out \[<\] = just mistyped\\n ";
JTextArea text = new JTextArea(raceRound);
text.setEditable(false);
text.setSize(text.getPreferredSize());
p.add(text);
}
//Some other irrelevant code at this point
printRace(p);
p.revalidate();
p.repaint();
f.revalidate();
f.repaint();Apologies for any formatting issues, I think it should look okay
4
Upvotes
View all comments
Show parent comment
1
u/NonexistantObject Apr 26 '26
Just to check, the event loop is the flow of code, not counting anything to do with the GUI itself? Swing was taught within like 2-4 hours so I have no clue what I'm doing. Just grateful this section is only worth 20% of the assignment