paintcomponent

Only one object will Render to Screen

不问归期 提交于 2019-12-11 05:19:56
问题 I'm trying to make it so that both squares appear on the JFrame but only the one that I make last in the main method apperas and the other one does not. Have been trying to figure this out for about 3 hours now and wanna smash my computer screen. Any help would be AWESOME. Thank you. public class Main extends JFrame{ static Main main; static Enemy square, square2; Render render; Main(){ render = new Render(); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500,500);

paintComponent not being called when label moved

。_饼干妹妹 提交于 2019-12-11 03:57:35
问题 I have a simple JPanel (otherJPanel) with a label below, both inside another JPanel (mainJPanel). mainJPanel overrides paintComponent , and repaint() is called manually elsewhere and the label text and the background of otherJPanel are set dynamically. However, when I move the label inside otherJPanel then paintComponent is never called. Any idea why? To test this I have created the test project below with labels in both positions. However, with this paintComponent is not called within the

Can not draw oval on a JPanel

故事扮演 提交于 2019-12-11 03:24:52
问题 I have a JFrame created with GUI builder of Netbeans, which contains a JPanel only. I have created a method getPanel for getting a reference to this JPanel: public class ShowDrawings extends JFrame { public ShowDrawings() { initComponents(); } public JPanel getPanel(){ return panel; } private JPanel panel; } In my main function I am doing: public class Main { public static void main(String[] args){ ShowDrawings sd = new ShowDrawings(); sd.setSize(800, 600); Graphics g = sd.getPanel()

How to update JTextFields in a GridLayout?

痞子三分冷 提交于 2019-12-11 03:08:59
问题 I have a MainPanel which uses the Gridlayout . Consequently I have created four JPanel classes for the: NORTH, EAST, CENTER and EAST layouts respectively. I then add all four to my MainPanel . However, on my WEST panel I use another grid layout to store JButtons and JTextFields . I want to constantly update my JTextFields as they display a value (that changes when a button on another panel is clicked). How do I allow that value to be changed when the JFrame is running? I tried using

Drawing inside multiple JPanels

感情迁移 提交于 2019-12-11 02:38:12
问题 I have three JPanels inside a main Frame. Clockwise from the left, in the first panel I plan to have some controls which dictate the drawing on the panel 2. The third bottom panel will show some informations. What I understand is, I have to override paintComponent so that I can achieve the desired effect on the second panel. Right now I just want to test it, whether I can draw simple texts on this panel. But in fact, I am having problem to draw anything in any of the three panels. The code is

the five top rows of the oval are erased. why?

这一生的挚爱 提交于 2019-12-11 02:35:11
问题 I'm really confused, I tried setting the oval to be exactly inside the red JPanel and the oval went 5 pixels too low. I tried to change y1 to -5 so it would be exactly in the JPanel, the oval moved to the right place but the five top rows of the oval were erased why did these things happen? and how do I place the oval in the middle of the JPanel? package il.co.atlantis; import javax.swing.*; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; public class PanelExample

jPanel is not refreshing until I resize the app window

半腔热情 提交于 2019-12-11 02:18:20
问题 I have one problem with my jPanel. I have a button which PNG image from String input (math formula) and then it will repaint the old image in jPanel. And there goes the problem. The image got changed, but the jPanel wont repaint until I manually resize the app window. Looks like the Panel wont repaint until that resizing. But I have no idea how to do it in that button. I tried this and this but no change. btw. I am using GUI Builder in netbeans. My code... first attempt: public class

I can't get graphics to draw on my panel/canvas/window in my Java program (swing). Any Ideas?

佐手、 提交于 2019-12-11 01:53:33
问题 I can't get graphics/text to draw on my panel/canvas/window in my Java program (using swing). I even tried breaking it up into two classes, with the paintComponent in one (extends JPanel) and other stuff in another class (extends JFrame). I've tried a panel with a Canvas and without a Canvas (both the same results). I can't get anything to draw in the blue area. If I remember correctly, when I tried it with no panels at all, I did see graphics. I've successfully done this program in text (no

Does g.drawImage() render only the part of the image visible on a JPanel, or does it “keep in mind” the rest of the image?

折月煮酒 提交于 2019-12-11 01:11:24
问题 Let's say we have the following code: (in a class that extends JPanel ): public void paintComponent(Graphics g) { g.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null); } If dx1 and dy1 are negative or dx2 and dy2 are larger than the width of the JPanel (in other words, part of the image will be off-screen), does drawImage() adjust what is rendered so that it only "pays attention to" the part visible on the JPanel ? I am curious about this because if I draw a very large image on

call paintcomponent for a jpanel in jframe

陌路散爱 提交于 2019-12-10 21:36:37
问题 I have a JFrame with a JPanel on it ( JPanel is private in JFrame ). Now I want to override JPanel by using paintComponent method. How can I do that? 回答1: When you create your instance of JPanel , (assuming you're doing it this way), do this: JPanel panel = new JPanel(){ @Override public void paintComponent(Graphics g){ // paint code } }; The other alternative is to create a private class which extends JPanel . For example: public class OuterClass{ // fields, constructors, methods etc..