Timeline for Swing - UI changes are not affected
Current License: CC BY-SA 4.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 8, 2023 at 15:07 | vote | accept | Giorgi Chapidze | ||
Dec 8, 2023 at 11:06 | answer | added | Gilbert Le Blanc | timeline score: 1 | |
Dec 8, 2023 at 9:26 | comment | added | MadProgrammer |
" How am I gonna reuse the graphics object? I want to draw from generateMaze method, right?" - Painting can occur for any number of reasons, most of which you don't control. This also means that you perform you paint pass as quick as possible. Instead of trying to generate the maze each time the paint method is called, generate on the class creation and cache the data, use this to render the maze, or as matt has suggested, render it to a BufferedImage , but you might have issues if you want it to resize dynamically
|
|
Dec 8, 2023 at 9:24 | comment | added | MadProgrammer |
setDoubleBuffered(true); is pointless, JPanel is already double buffered, you should also be calling super.paintComponent first before doing any custom painting
|
|
Dec 8, 2023 at 9:06 | comment | added | matt |
Do not reuse a graphics object. The idea in paintComponent is to just draw the component. If you want to build and modify an image, then use a BufferedImage . You can call getGraphics then modify the image with that graphics. Then you don't even need a paintComponent, just use a JLable with an ImageIcon.
|
|
Dec 8, 2023 at 8:53 | comment | added | Giorgi Chapidze | Thanks for the reply. How am I gonna reuse the graphics object? I want to draw from generateMaze method, right? | |
Dec 8, 2023 at 8:21 | comment | added | matt | It looks like you don't understand swing painting/drawing. You're calling generateMaze in your paintComponent. Don't do that. In removeWall you're calling "SwingUtilites.invokeLater" and attempting to use the graphics obect passed in for paintComponent. That is fundamentally broken. Do not change anything in your paintComponent, just paint. | |
Dec 8, 2023 at 8:13 | history | edited | Giorgi Chapidze | CC BY-SA 4.0 |
added 1 character in body
|
S Dec 8, 2023 at 8:10 | review | First questions | |||
Dec 8, 2023 at 15:10 | |||||
S Dec 8, 2023 at 8:10 | history | asked | Giorgi Chapidze | CC BY-SA 4.0 | created from wizard |