repaint

JButton showing up in the wrong spot after repaint is called

不问归期 提交于 2021-02-10 20:21:33
问题 I am trying to add a couple of JButton objects to my GUI program in Java and it is adding them to the JPanel (which is the main file of the program) but it is appearing in the incorrect spot. It is showing op at point [0, 0] and the action that is linked to it is happening at the correct spot. The rest of the elements on the panel are Images so the repaint method is called very often. private void init() { setLayout(null); setBackground(new Color(r, g, b)); addMouseListener(this);

Is repaint executing too slow?

拜拜、爱过 提交于 2021-02-10 19:48:15
问题 I have the following: import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JLayeredPane; import javax.swing.JFrame; import javax.swing.BorderFactory; import java.awt.event.MouseListener; import java.awt.event.MouseEvent; import javax.swing.ImageIcon; import java.awt.GridLayout; import java.awt.Dimension; import java.awt.Color; import java.util.Random; class Cell extends JLayeredPane { private JLabel image1; private JLabel image2; private JLabel image3; private Random rand;

Is repaint executing too slow?

筅森魡賤 提交于 2021-02-10 19:47:58
问题 I have the following: import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JLayeredPane; import javax.swing.JFrame; import javax.swing.BorderFactory; import java.awt.event.MouseListener; import java.awt.event.MouseEvent; import javax.swing.ImageIcon; import java.awt.GridLayout; import java.awt.Dimension; import java.awt.Color; import java.util.Random; class Cell extends JLayeredPane { private JLabel image1; private JLabel image2; private JLabel image3; private Random rand;

Swing refresh cycle

一个人想着一个人 提交于 2021-02-07 07:45:17
问题 I'm trying to understand when to use revalidate/repaint/pack. Surprisingly I haven't found much detailed under-the-hood documentation (feel free to link). So far I have understood that this is all the responsibility of the RepaintManager. paint/repaint refer to what sees as dirty/clean pack/validate/revalidate refer to what is valid This article on Oracle explains that calling a repaint enqueues a job on the Event Dispatcher Thread that will in turn call paintImmediately() on the component

Swing transparent background not being repainted

心不动则不痛 提交于 2020-07-22 21:36:39
问题 I have a problem using transparent backgrounds in Swing. There are a lot of artefacts produced as swing is not repainting changed regions. As far as I can tell there are 2 out-of-the-box ways to use transparent backgrounds: an opaque component with transparent color set as background (left txt field) Problem : the transparent part of the background is never refreshed -> Artefacts. an non-opaque component with transparent color set as background (right txt field) Problem : background is not

Swing transparent background not being repainted

落花浮王杯 提交于 2020-07-22 21:36:24
问题 I have a problem using transparent backgrounds in Swing. There are a lot of artefacts produced as swing is not repainting changed regions. As far as I can tell there are 2 out-of-the-box ways to use transparent backgrounds: an opaque component with transparent color set as background (left txt field) Problem : the transparent part of the background is never refreshed -> Artefacts. an non-opaque component with transparent color set as background (right txt field) Problem : background is not

Artifacts showing when modifying a custom QGraphicsItem

孤人 提交于 2020-05-29 08:23:21
问题 I'm currently developping a small vector drawing program in wich you can create lines and modify them after creation (those lines are based on a custom QGraphicsItem). For instance, the picture below shows what happens when the leftmost (marked yellow) point of the line is dragged to the right of the screen, effectively lengthening the line : Everything works fine when the point is moved slowly, however, when moved rapidly, some visual artifacts appear : The piece of code I'm using to call

Artifacts showing when modifying a custom QGraphicsItem

为君一笑 提交于 2020-05-29 08:23:12
问题 I'm currently developping a small vector drawing program in wich you can create lines and modify them after creation (those lines are based on a custom QGraphicsItem). For instance, the picture below shows what happens when the leftmost (marked yellow) point of the line is dragged to the right of the screen, effectively lengthening the line : Everything works fine when the point is moved slowly, however, when moved rapidly, some visual artifacts appear : The piece of code I'm using to call

repaint components in a loop

我只是一个虾纸丫 提交于 2020-02-25 04:19:22
问题 I'm creating a simple game and I'd like to repaint the board after every move. So, after I call move(), what I would like to do is this: (by the way, a View is a JComponent that holds pieces; since the number of pieces has changed after the move, it needs to be repainted) for(View v : views){ v.repaint(); } It's not working. When I call repaint() on a single View, it works fine. I tried using paintImmediately , and revalidate , and update ... nothing works within the loop. Any ideas? Thanks