paintcomponent

How can I add a button to paintComponent panel in java?

孤者浪人 提交于 2020-06-23 18:36:13
问题 The app is an option menu which shows a drawing depending on which button the user presses. I have a container panel with a CardLayout which manages the other panels. I want to show the drawing in my paintComponent Panel, but I also want a button at the bottom of the screen so the user can go back to the main menu. I tried adding it like this but the button didn't appear: CardLayout c1 = new CardLayoutl; JPanel cont1 = new JPanel(); cont1.setLayout(c1); JPanel panel1 = new JPanel(); panel1

PaintComponent not being called with JPanel

≯℡__Kan透↙ 提交于 2020-01-30 12:25:05
问题 when I run this code PaintComponent is never called because the "painted" message is never printed and I do not know why? can anyone help? public class DisplayManager extends JPanel { public static final int WIDTH = 700, HEIGHT = 900; public Bottle bottle1 = new Bottle("res/bottleimage.png"); public Slider slider1 = new Slider(); public void initDisplay() { JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(new

java.lang.NullPointerException on super.paintComponent(g);

你离开我真会死。 提交于 2020-01-25 10:52:05
问题 I'm getting a java.lang.NullPointerException on my super.paintComponent(e) line, I have looked at a few tutorials but I'm unsure of what I'm doing wrong. Heres my Main class: package pack; public class Main { public static void main(String[] args){ @SuppressWarnings("unused") Display display = new Display("The JFrame", 510, 510); Game game = new Game(); game.start(); } } Display class: package pack; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; public class

why is paintComponent() never called by repaint()?

有些话、适合烂在心里 提交于 2020-01-25 05:59:10
问题 I've been working on an program that draws custom JComponents onto a JLayeredPane however all calls to repaint() on the components seem to do nothing yet the paintComponent method is invoked automatically when the window is re-sized. I have been following some of the advice given here: Why is paint()/paintComponent() never called? But none of the solutions seem to fix my problem, update swing components on the EDT, setting component size manually before calling repaint(), calling super

why is paintComponent() never called by repaint()?

北战南征 提交于 2020-01-25 05:57:44
问题 I've been working on an program that draws custom JComponents onto a JLayeredPane however all calls to repaint() on the components seem to do nothing yet the paintComponent method is invoked automatically when the window is re-sized. I have been following some of the advice given here: Why is paint()/paintComponent() never called? But none of the solutions seem to fix my problem, update swing components on the EDT, setting component size manually before calling repaint(), calling super

Anti-aliased JLabel

我怕爱的太早我们不能终老 提交于 2020-01-24 10:50:07
问题 I've attempted to create a custom anti-aliased JLabel , but my text remains rigid. Why doesn't this work? The answers to similar questions include more verbose solutions, but I want to know why this isn't working. Edit: Here's an SSCCE: import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import javax.swing.JFrame; import javax.swing.JLabel; public class Tester { public static void main(String[] args) { SmoothLabel label = new SmoothLabel

Trying to draw lines with JPanel

一笑奈何 提交于 2020-01-22 16:14:06
问题 I am trying to draw lines using JPanel and I have hit somewhat of a wall. I can get two sides down but once it comes to subtracting from the x cord it all goes wrong. package GUIstuff; import java.awt.Graphics; import javax.swing.JPanel; public class DrawPanel extends JPanel{ public void paintComponent (Graphics g){ super.paintComponent(g); int width = getWidth(); int height = getHeight(); int drawCounter = 0; // counters for all the while statements int drawCounter2 = 0; int drawCounter3 = 0

How can I draw a curved line segment using QuadCurve2D.Double?

五迷三道 提交于 2020-01-21 19:18:26
问题 Here is the line of code where I declare the curve: QuadCurve2D.Double curve = new QuadCurve2D.Double(50,100,100,170,150,100); Now what code can I use to draw this curve? I tried something like: g.draw(curve); but obviously that didn't work. Any suggestions? 回答1: I've made a minimum test case of what I think your describing here. This program works but I can't really help you unless I can see the code you are working with. import java.awt.geom.*; import java.awt.*; import javax.swing.*;

How can I draw a curved line segment using QuadCurve2D.Double?

丶灬走出姿态 提交于 2020-01-21 19:18:15
问题 Here is the line of code where I declare the curve: QuadCurve2D.Double curve = new QuadCurve2D.Double(50,100,100,170,150,100); Now what code can I use to draw this curve? I tried something like: g.draw(curve); but obviously that didn't work. Any suggestions? 回答1: I've made a minimum test case of what I think your describing here. This program works but I can't really help you unless I can see the code you are working with. import java.awt.geom.*; import java.awt.*; import javax.swing.*;

Drawing an image on top of an image in a JComponent erases part of the bottom image

狂风中的少年 提交于 2020-01-17 05:38:41
问题 I am making a 2d game and I need to draw an image on top of another. After I draw the first image(the larger one, jpg), the second image(the smaller one,png) erases from where the second image is to the lower right hand corner. Like this: I have looked into this a bit, and it was suggested that I use buffered images, so I did that with both images and the problem remains. Here is one post I looked at: How to draw an image over another image?. I have also seen some people suggesting graphics2d