paintcomponent

Rectangle is not drawn on top

前提是你 提交于 2020-01-15 23:55:19
问题 I have a class "Map" which extends JPanel. I add it to a class that extends a JFrame. public void paintComponent(Graphics g) { super.paintComponent(g); int width = Math.abs(startX - endX); int height= Math.abs(startY - endY); g.setColor(Color.RED); g.fillRect(startX, startY, width, height); } My class "Map" also contains a label with an image in it. If the image is smalled than the window, when I draw a rectangle it is seen. In short, it is under the label. 回答1: paintComponent is the "bottom"

Java .drawImage : How do I “unDraw” or delete a image?

拈花ヽ惹草 提交于 2020-01-14 18:06:15
问题 I need a certain image to be redrawn at different locations constantly as the program runs. So I set up a while loop that should move an image across the screen, but it just redraws the image on top of itself over and over again. What am I doing wrong? Is there a way to delete the old image before drawing it in a new location? JFrame frame = buildFrame(); final BufferedImage image = ImageIO.read(new File("BeachRoad_double_size.png")); JPanel pane = new JPanel() { @Override protected void

Intercepting or delegating events with overlapping components

扶醉桌前 提交于 2020-01-13 13:11:17
问题 I have two JPanels equal in size, one over the top of the other. The top layer serves as a drag selection panel, and the other one has other components added to it. My problem is that the mouse event handlers of these added components aren't triggered, because they are handled by the overlaying panel instead. How can I still drag over the top of these added components, but still have mouseEntered and mouseExited enabled for the underlaying components? Here is a screenshot: As you can see, the

how to draw multiple rectangles

只谈情不闲聊 提交于 2020-01-11 13:41:27
问题 so I am trying to make a simple program where you click on the screen and it creates a block that falls and collides with a larger block beneath and sticks to it. Kind of like a simple collision program. The problem is when I create one block it deletes the block previously. I made an array, but it still does this. Do any of you know what Im doing wrong? Im sure its a simple fix. public class Screen extends JPanel implements Runnable { public static JLabel statusbar; //displays a status bar

Painting over the top of components in Swing?

自闭症网瘾萝莉.ら 提交于 2020-01-11 08:25:34
问题 I have a JPanel added to a JViewport , and the panel has several other panels added to it. I'm trying to implement a dragging selection, where you can select more than one component by dragging the mouse. The only problem I'm facing is that the selection rectangle is being painted behind the components added to the main JPanel . How can I paint over the top of them? My structure is as follows: JFrame -> ContentPane -> JLayeredPane -> JScrollPane -> JPanel -> JPanel [] . Design draft for

JPanel doesn't update until resize Jframe

核能气质少年 提交于 2020-01-09 03:49:49
问题 I subclass JPanel to overwrite paintComponent(Graphics), I want to draw an image onto jpanel in a jframe. But my image hasn't shown up until I make a change to jframe's size. This is my code: public class ImagePanel extends JPanel{ public void setImage(BufferedImage bi) { image = bi; revalidate(); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); if(image != null) { g.drawImage(image, 0, 0, this); } } } 回答1: Verify that you invoke setVisible() after adding

Change color of JComponent after paintComponent has finished

廉价感情. 提交于 2020-01-06 11:44:09
问题 I am testing one small widget class that extends JComponent the constructor for the widget contains one vector and sets PreferredSize of the component, then there is the paintComponent: public void paintComponent(Graphics g){ g.setColor(Color.RED); g.drawString("this is text one", 10, 10); //here I draw some shapes based on the //vector size and integers } } the component is drawn correctly and after that i call some other methods in main, when the methods finish their jobs i call widget

paintComponent not being called at the right time

穿精又带淫゛_ 提交于 2020-01-06 09:02:00
问题 I'm trying to write an app that goes something like this: - Display a dialog - When user clicks OK, close dialog, go to main app Here are the relevant code snippets: public class Owari extends JPanel implements ActionListener, MouseListener, Runnable { // FIELDS JFrame frame; JTextField IP; String IPAddress; static final int SERVER_MODE = 0; static final int CLIENT_MODE = 1; int mode; OwariBoard board; public static void main( String[] args ) { SwingUtilities.invokeLater( new Owari() ); }

paintComponent not being called at the right time

a 夏天 提交于 2020-01-06 09:01:00
问题 I'm trying to write an app that goes something like this: - Display a dialog - When user clicks OK, close dialog, go to main app Here are the relevant code snippets: public class Owari extends JPanel implements ActionListener, MouseListener, Runnable { // FIELDS JFrame frame; JTextField IP; String IPAddress; static final int SERVER_MODE = 0; static final int CLIENT_MODE = 1; int mode; OwariBoard board; public static void main( String[] args ) { SwingUtilities.invokeLater( new Owari() ); }

Image Drawing Works for JFrame, But Not JPanel

北城余情 提交于 2020-01-04 07:54:09
问题 I'm working through some simple applications to get familiar with Swing and running into problems. I'm attempting to have a frame containing an image (in a panel) along with buttons to zoom in/out from the image. I have been able to make a frame with the added image work fine (albeit with some frame sizing issues, but that is another story), however, when I call the same component class to add it to a panel, nothing appears. I'm hoping one of you can help shed light on the situation. CODE: