Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I make it so that a JPanel updates itself once the window scrolls?
    primarykey
    data
    text
    <p>I'm new to Java so this is probably pretty simple, but I'm not sure how to make it work.</p> <p>Basically, I have a class which I use to draw a grid, which extends JPanel. I put this class in a window, inside a JScrollPane. The scroll works the way I want it to, except the drawing inside my class doesn't update itself once the window scrolls. It does update if the window is resized though.</p> <p>I think I'm supposed to use events/listeners or something like that, but I'm not sure where to start looking.</p> <p>edit: also, when i open one of the menus and it overlaps on the drawing, the region that was covered by the menus isn't updated.</p> <p>Okay, let's try again: I have a class called draw. Then I have a GridBagLayout out of draws. This creates the grid I need. I have an object moving around the grid, so this way I can update the grid without having to calculate myself the rectangles that have to be updated.</p> <p>Then this grid is inside a JScrollPane, which is not subclassed. I use pack() when I create my Window, but the thing is, the Window may be bigger than the resolution allows, so I need it to be scrollable. The scroll works for me, but it doesn't update the image when I use it. However, resizing the window does update it.</p> <p>What I want is a way to redraw all my window when I click the JScrollPane. And now, I also need to redraw the whole thing (or some parts, I'll see that later) once I access the menus, because the draw parts of the grid under the menus are not updated.</p> <p>That's the best way I can describe it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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