Sorry about the vague title, it's hard to explain what I mean without an extensive description.
I have a CPU simulation program that I have built, and within the GUI of this program I have a JTextArea that is populated with strings of text that look like the following
0x01 : $00 (0) [BRK]
These lines of text represent the values held inside RAM memory of size 256 bytes. The JTextArea contains 256 of these lines, each one displaying what is being held in that particular memory address. It looks something like this
0x01 : $00 (0) [BRK]
0x02 : $00 (0) [BRK]
0x03 : $00 (0) [BRK] <-- PC
0x04 : $00 (0) [BRK]
0x05 : $00 (0) [BRK]
...
0xFF : $00 (0) [BRK]
Also present is the PC arrow that displays the current position of the program counter as the memory is stepped through. With each step of the program, the PC is incremented by two. As such, if the PC is pointing at 0x03, and the program is stepped, the PC will then be incremented to 0x05.
My problem, is that my JTextArea can only display 12 of these strings at one time due to its size, this means that after 6 steps the PC arrow will disappear off the bottom of the TextArea, and the user will have to manually scroll down to see it again.
Is there a way that I can make it so that as the PC arrow descends down the list of memory addresses, the JTextArea scrolls with it so that the PC arrow is always in the center of the TextArea no matter how far down the TextArea it is?
I have tried using the following code to achieve this, but it doesn't seem to cause any difference at all.
int caretVal = 0;
int pc = 0;
try
{
for(int i = 0; i < steps; i++)
{
step();
pc = mos6502.getCpu().getPc();
}
if(pc > 5)
caretVal = pc + 11;
gui.refreshGui();
gui.setMMCaret(caretVal);
}
catch(...)
{
etc...
}
I am assuming that this method doesn't actually do what I believe it to. But I'm not too sure.
Edit: Also, I assume this is relevant. After every step in the program, a gui.refreshGui()
method is called. This method causes the JTextAreas to be updated with new information, this causes the JTextArea's position to shoot to the bottom, as it's being filled with new information.