repaint

repaint in a loop

久未见 提交于 2019-11-27 05:38:16
I am writing a game using Java Swing. I want to paint each time a loop executes with a small delay in between to create a cascade effect on screen. I believe that the efficiency routines in the system are collapsing the calls to repaint() into a single call. At any rate, the changes all occur at once after the total delay. Is there some way to force the system to repaint immediately and then delay on each iteration of the loop? My Code: for(int i=0;i<10;i++){ JButton[i].setBackground(Color.WHITE); JButton[i].repaint(); Thread.sleep(2000); JButton[i].setBackground(Color.GRAY); JButton[i]

JLayeredPane and painting

我只是一个虾纸丫 提交于 2019-11-27 05:21:24
I am writing an application which has a JLayeredPane (call it layers) containing two JPanels in different layers. I override the paintComponent method of the JPanel at the bottom (call it grid_panel) so it paints a grid, and the the paintComponent method of the one at the top (call it circuit_panel) so it paints a circuit. Here's a summary of the structure: layers - |-circuit_panel (on top) |-grid_panel (at bottom) I want the grid_panel to stay static, ie, not to do any repaint (except the initial one) since it does not change. The trouble is, whenever I call circuit_panel.repaint(), grid

Preserve painting after resize or refresh

两盒软妹~` 提交于 2019-11-27 04:54:00
问题 How can I preserve the painting I drew on a picturebox? I draw a circle, and fill it via the ExtFloodFill API. This works fine. When I resize the form (or minimize it) and resize it back to its original size part of the painting is gone. When I refresh the picturebox the painting will be gone completely I tried to repaint it in the Paint event, but this caused it to be repainted continuously as the painting itself triggered the Paint event as well. See below for a test project. When you click

<img /> vs background-image (css) in performance

人走茶凉 提交于 2019-11-27 01:47:32
问题 I am building a site that is using a scrolling plugin that basically animates the scrolling. I am quite concern about performance as if I insert some images in the site, it looks quite choppy when scrolling/animating. The main problem I can detect with images is the reflow/repaint issue, when the image doesn't have the correct dimensions and therefore is scaled (I have to deal with this, I know about the best practice). With this statement in mind (images will be scaled). What should be

How to remove all components from a JFrame in Java?

给你一囗甜甜゛ 提交于 2019-11-27 01:30:19
问题 I'm writing a program where I have a JFrame and I want to remove all components from it, then add just one component to it and repaint the frame. What I have so far is something like the code below (called in an object that implements JFrame, where StartPanel implements JPanel): removeAll(); startPanel = new StartPanel(); startPanel.setVisible(true); add(startPanel); revalidate(); repaint(); However, when I run the code it shows an empty window (not the startPanel) and when I minimize/resize

Simple animation using Thread.sleep() in ActionListener

为君一笑 提交于 2019-11-26 22:10:22
问题 I'm having trouble with this code I am using to create a roulette wheel. The goal is to spin the wheel when I click the "SPIN!" button. I have done this by creating a for loop that should change the status of the wheel from true to false, which changes the orientation. This, when done fast enough, should create the illusion of movement. THE PROBLEM I AM HAVING : is that my wheel is only repainting after the whole for loop is done, despite my placement of the repaint(). So, it only spins one

Problems with Java's Paint method, ridiculous refresh velocity

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 21:07:33
I'm developing a very simple version of R-Type as work for the university, but despite it works, the craft velocity is a lot of slow, so the movement is ugly and clumsy. I use the method repaint for refresh the screen, there are others methods or ways best than it? Video of Movement Paint method at main Panel @Override public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.drawImage(fondo, 0, 0,1200,600,this); pj.paint(g2); g2D=g2; } PJ's paint method public void paint

How is CSS applied by the browser, and are repaints affected by it?

落花浮王杯 提交于 2019-11-26 19:12:15
问题 Let's say we have an HTML page with a single stylesheet <link> . How does the browser take the rules in this stylesheet and apply it to the HTML? I'm not asking about how to make it faster, I want to know how the rendering itself is handled. Does it apply each rule one-by-one as it parses the stylesheet and render the result progressively? Or, are the CSS file's contents completely downloaded, then fully evaluated, and then applied to the HTML all at once? Or something else? I ask this after

Is the Swing repaint() method still safe to use outside the EDT in Java 7+?

别等时光非礼了梦想. 提交于 2019-11-26 17:48:09
问题 I know that it used to be considered safe to call repaint() and a few other selected methods from any thread even with Swing's threading model, however I was recently told in a comment that this is not so. Google found a lot of older discussion saying it is safe but nothing recently. All of the official references that used to say it is safe seem to have disappeared, and I found a few people in various forums discussing how it was no longer safe. I cannot find anything official to confirm

Swing Worker : function get()

放肆的年华 提交于 2019-11-26 16:41:48
My problem is that I don't understand how the swingworker works because what I'm trying to do is to make fa=worker.get() because I have a long method which compute a lot of points running in background because I don't want to freeze my interface and I want to get her results to paint the component image. But I don't understand where it goes when I do fa=worker.get() because my console prints "titi" and I put a lot of other printing to see the next part of program reached but no one is printed. Please help me to know where the compilation goes after get() or while it execute it and if you have