repaint

repaint() Method in Java

大城市里の小女人 提交于 2019-12-06 04:01:08
问题 I am playing around with the Java graphics class a little bit and I was just wondering--when is it necessary to call the method repaint() ? I tried commenting it out and it didn't seem to affect my output GUI. I've seen it used a lot in Java GUI code that I've read, though. Would anyone mind explaining when to use it and when not to use it? 回答1: The repaint() refreshes the view (component), so whenever you make any change on the component, you must call it. For instance, if you rotate the

Paint in a part of JPanel without repaint the rest

谁都会走 提交于 2019-12-06 03:48:53
问题 I'm trying to make a Mastermind in Java. The code isn't really difficult, but I want to have a very good interface. I have a JPanel which take all my JFrame, and I paint this JPanel with surchargind repaint() method: public void paint(Graphics g) //méthode permettant de dessiner les éléments sur la carte { super.paintComponents(g); Graphics gr; gr = MasterMindPane.getGraphics(); img = MasterMindPane.getToolkit().getImage("images/plateau4-8.jpg"); gr.drawImage(img, 0, 0, 600, 720, this); gr =

Why doesn't my repaint work?

风格不统一 提交于 2019-12-06 02:26:22
I'm stuck with a problem considering my Display class, which extends Canvas. A single thread is running within the very same class. In this thread, the repaint method is called. However, while the thread works fine, the paint method is never called! Here's my code (I left out everything unrelated): package display; public final class Display extends Canvas implements Runnable { private static final long serialVersionUID = 1L; private Frame frame; private GraphicsEnvironment ge; private GraphicsDevice gd; public BDisplay() { ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); gd = ge

Label text doesn't get updated until the whole loop is completed

自作多情 提交于 2019-12-06 02:10:27
I have a Winform program that does some calculations when the user clicks on a button and then calls the picturebox paint event to draw a new BMP based on the results of the calculations. This works fine. Now I want to do this 100 times and every time the picturebox is refreshed, I want to see the iteration that it's currently in by updating the text on a label as per below: private void button2_Click(object sender, EventArgs e) { for (int iterations = 1; iterations <= 100; iterations++) { // do some calculations to change the cellmap parameters cellMap.Calculate(); // Refresh picturebox1

Swing JPanel won't repaint

泄露秘密 提交于 2019-12-05 20:33:37
问题 I have a simple object which extends JPanel , when the update() method is called on this object it it meant to add some labels to the panel and then repaint. However the labels do not show up after the update method is called, below is the code for update: public void update(){ GridBagConstraints constraints = new GridBagConstraints(); if(cardsHidden){ for(int i = 0; i < 2; i++){ constraints.gridx = i; constraints.gridy = 0; JLabel card = new JLabel(PlayingCards.cardImages[PlayingCards.CARD

java applet paint method trouble

江枫思渺然 提交于 2019-12-05 19:57:54
In code I am calling repaint() method from init() method but Output is not as per I expect. I called repaint() method 10 times but It called paint() only once(See Screenshot of O/P). Am I making any mistake. please help me. Thanks code import java.awt.*; import java.applet.Applet; /* <applet code="test" height=300 width=300> </applet> */ public class test extends Applet { int x,y; public void init() { x=5; y=10; for(int i=1;i<10;i++) { System.out.println("From init "+i); x+=(i*2); y+=(i*3); repaint(); } } public void paint(Graphics g) { System.out.println("Paint"); g.drawLine(50,50,x,y); } }

Java repaint not working correctly

对着背影说爱祢 提交于 2019-12-05 09:59:15
i use the java repaint method , it repaints, but the update is only seen when I either click on the canvas or resize the panel. How can I fix this ? What causes it? You need to call the method revalidate(). This forces the layout manager to update / repaint all its components. repaint() isn't actually repainting, it's just requesting a repaint of the component. Marc Kirschner It may be helpful to simply grab the Graphics object from the component you wish to paint. Then just invoke a paint method on the Graphics object. For example: g = component.getGraphics(); draw(g); 来源: https:/

Why does my custom Swing component repaint faster when I move the mouse? (Java)

十年热恋 提交于 2019-12-05 07:13:47
I am trying to make a 2D game with Java and Swing, and the window refreshes too slow. But if I move the mouse or press keys, the window refreshes as fast as it should! Here is a GIF showing how the window refreshes quickly only when I move the mouse. Why does the window refresh slowly like that? Why does the mouse and keyboard affect its refresh rate? How, if possible, do I make it refresh quickly all the time? Background Info I use a javax.swing.Timer to update the game state every 1/25 seconds, after which it calls repaint() on the game panel to redraw the scene. I understand that a Timer

How to update Android Views upon modifications?

拈花ヽ惹草 提交于 2019-12-05 05:27:27
I have some methods in my View that modify some of the shapes that are drawn when called. In Java in order to make sure the component is updated I would call repaint() . Is there something that will make sure my view is updated correctly? I had read somewhere that calling invalidate() in the onDraw() method would keep things up to date and therefore I wouldn't need to have something like repaint() in my methods that modify that shapes that are drawn. Is this correct, or is there something else I have to do? EDIT To add in an example, a method I call in my view is: public void setLineThickness

Java graphics repaint problem

▼魔方 西西 提交于 2019-12-05 04:52:50
问题 Having trouble with a simple paint pad in java. Issues with getting my clear button to repaint. The array is clearing but not repainting. Can anyone spot my problem or is there any different way of generating a clear button for this code. public class DrawingPanel extends JPanel { private double x1=0; private double x2=0; private double y1=0; private double y2=0; private ArrayList<Shape> myArr = new ArrayList<Shape>(); //private ArrayList<Shape> clearMyArr = new ArrayList<Shape>();