repaint

Swing rate limiting

梦想与她 提交于 2019-11-28 02:07:44
问题 I have a long repaint operation that I would like to rate-limit, ie make sure it gets called once every N milliseconds at most. My current solution is somewhat unsatisfactory: I use a Swing Timer with a short duration, which I restart() whenever I get an event. This make sure that a repaint is not triggered if events happen within an N milliseconds window (i.e. the repaint will happen after an event and an N milliseconds "quiet" period has elapsed). What I would like is to make sure the

paint() and repaint() in Java

a 夏天 提交于 2019-11-27 13:59:46
I've spent maybe the last two hours browsing and reading up on these methods and the Graphics class, and maybe I'm stupid, haha, but I'm just not understanding them. What are they for? I understand that they're supposed redraw or update components on the screen, but I have never understood why this is required (I'm new to this). For example, if I'm moving a JLabel around the screen, a call to setLocation() moves it just fine. Is that a scenario in which repaint() isn't required? In which scenarios is it useful, and why? Apologies if you feel that this is a question that could be solved using

Updating ImageIcon in JTree without repainting the Tree?

折月煮酒 提交于 2019-11-27 09:51:32
Basically I edit an attribute private string status="OK" in the UserObject() of a DefaultTreeNode() . I have a CustomRenderer which implements DefaultCellRenderer , which sets the Icon by rendering the "OK" attribute of UserObject of a TreeNode . Originally, when I select a node, the icon changes. I am using Tree.revalidate() & Tree.repaint() , and the change is being reflected. However, I am not sure if this very efficient. What would be the proper way of doing this? I tried doing TreeModel.nodesChanged(new DefaultMutableTreeNode(myUserObject)) but the TreeNodeChanged event will not fire. So

paintComponent draws other components on top of my drawing

人走茶凉 提交于 2019-11-27 09:42:08
I'm trying to build a simple paint tool. The mouseDrag events creates a new ellipse and causes my JPanel to repaint() . This works fine so far. However, if I press any button (or any other UI component) before firing the mouseDrag event for the first time, the button is painted in the upper left corner of my panel. I have isolated the code into this test application: import java.awt.BasicStroke; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing

repaint() in Java [duplicate]

99封情书 提交于 2019-11-27 09:06:45
Possible Duplicate: Java GUI repaint() problem? I write a Java code, but I have a trouble with GUI problem. When I add a component into JFrame object, then I call repaint() method in order to update the GUI but it doesn't work. But when I minimize or resize this frame, the GUI is updated. Here is my code: public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(460, 500); frame.setTitle("Circles generator"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); String input = JOptionPane.showInputDialog("Enter n:"); int n = Integer.parseInt

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

主宰稳场 提交于 2019-11-27 09:04:58
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 whether it is or isn't though - and I'd really like to see something explaining the logic of the change if

Java GUI repaint() problem?

强颜欢笑 提交于 2019-11-27 08:58:19
I have a JFrame. This JFrame contains a JButton. I click the JButton and 10 JTextFields are created. the problem: I cannot see them until "I force a repaint()" by resizing the window. Only then do I see the JTextFields created. CODE: JPanel points = new JPanel(); //Creating the JTextFields: for (int i=0; i<10; i++) { JTextField textField = new JTextField(); points.add(textField); } repaint(); this.repaint(); super.repaint(); points.repaint(); THANK YOU - after the for loop, I just called points.validate() and it worked... Tom Hawtin - tackline Container.add API docs sayeth: Note: If a

How to improve painting performance of DataGridView?

雨燕双飞 提交于 2019-11-27 08:21:42
(sorry for bad English) I have a big problem with performance of DataGridView when it re-paints. I'm using a DataGridView to show logs from an external application stream. Messages from the stream come in with a high frequency (less than 1 ms). If I add new row to the DataGridView immediately when each new message comes, the DataGridView doesn't have time to re-paint itself before the next message comes. A possible solution is to use a queue to collect messages and re-paint DataGridView every 100 ms with messages from queue. This is good but the DataGridView blinks when it auto-scrolls to the

Visual Artifacts appearing on JPanel

假装没事ソ 提交于 2019-11-27 08:14:58
问题 I am trying to create a program with 2 JPanel using BorderLayout . The center panel is for random drawing of rectangle while the south panel is for the buttons. I am getting a weird image of the button on the top left corner of the JFrame whenever I hover the mouse cursor over the North or South button. I did some research and found out that this could be the reason for having a transparent background. I tried using super.paintComponent(g) for the panel but the rest of the rectangles drawn

painting a particular button from a grid of buttons

北战南征 提交于 2019-11-27 07:16:59
问题 The following grid of buttons is defined as : JButton button_x = new RoundButton(); where RoundButton is defined as : public class RoundButton extends JButton { public RoundButton(String label) { super(label); this.setContentAreaFilled(false); Dimension size = this.getPreferredSize(); size.height = size.width = Math.max(size.height, size.width); this.setPreferredSize(size); } @Override protected void paintComponent(Graphics g) { if(!GameState.getIfComplete()) { // If the game is not complete