paintcomponent

Java - MouseListener Action Event in paintComponent

笑着哭i 提交于 2019-12-02 03:49:36
问题 Here i have a code which draws a rectangle on the mouseClicked position using the paintComponent.I can get the output message but anything related to graphics and .draw() wont work. Code: import java.awt.*; import java.awt.event.*; import javax.swing.*; public final class testclass extends JFrame { static JPanel p; Timer t; int x = 1; int y = 1; int xspeed = 1; int yspeed = 1; public testclass() { initComponents(); this.setBounds(100, 300, 500, 500); this.setDefaultCloseOperation(JFrame.EXIT

Keeping draw graphics - removing super.paintComponent

妖精的绣舞 提交于 2019-12-02 03:10:35
问题 I have a class named Foo that extends a class named Bar that extends JPanel and implements ActionListener. When I select Circle and click the draw button, I draw a circle, and when I press rectangle and click draw, it erases the previous shape and draws a rectangle. However, I want to keep all the shapes on the JPanel until I choose to click the erase button. So I removed the super.paintComponent(g) and it works, but it also causes buttons of class Bar to reappear in a glitchy manner. How can

no repaint while resizing when using .setPaint(gradient)

可紊 提交于 2019-12-02 03:08:35
As soon a I use gradients in my code, the repaint isn't done while resizing I get something like that while resizing (black rectangles where it has been resized, see image in the link below). And when i stop resizing, everything is drawn again, but only then. if I don't use g2d.setPaint(gradient); I have a quick redraw http://gui-builder.com/C41142775162.rar public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; //sample of the code GradientPaint gradient = new GradientPaint(startX, startY, greyColor1, endX, endY, new Color(120,120,120)); g2d.setPaint

JComponent size issue

本秂侑毒 提交于 2019-12-02 02:52:32
问题 I have a JComponent subclass that I am using to draw shapes onto my screen. In the constructor, I am trying to set ballX and ballY to half of the X and Y size values of the JComponent , and I think I am doing it wrong. I have looked this up a lot now, and cannot find a remedy. The code is as follows. Please bear in mind that this is my first real Swing/Graphics2D venture. public class PongCanvas extends JComponent { //Vars to hold XY values and Dimension values. private int batXDim, batYDim;

JComponent size issue

醉酒当歌 提交于 2019-12-02 02:05:46
I have a JComponent subclass that I am using to draw shapes onto my screen. In the constructor, I am trying to set ballX and ballY to half of the X and Y size values of the JComponent , and I think I am doing it wrong. I have looked this up a lot now, and cannot find a remedy. The code is as follows. Please bear in mind that this is my first real Swing/Graphics2D venture. public class PongCanvas extends JComponent { //Vars to hold XY values and Dimension values. private int batXDim, batYDim; private int b1X, b1Y; private int b2X, b2Y; private int ballRad, ballX, ballY; public PongCanvas() {/

Java - repaint(x, y, w, h) doesn't call paintComponent? (with SSCCE)

独自空忆成欢 提交于 2019-12-02 00:09:30
问题 I asked this before, but only theoretically, without an SSCCE. Now, I've created one, and the problem persists. I'd like to know why paintComponent is not called on repaint(x, y, w, h) , but is called on repaint() . Two classes: SANDBOX import java.awt.Dimension; import java.awt.FlowLayout; import javax.swing.JFrame; public class Sandbox { public static void main(String[] args) { JFrame f = new JFrame(); f.setMinimumSize(new Dimension(800, 600)); f.setLocationRelativeTo(null); f

Java - MouseListener Action Event in paintComponent

江枫思渺然 提交于 2019-12-01 23:53:20
Here i have a code which draws a rectangle on the mouseClicked position using the paintComponent.I can get the output message but anything related to graphics and .draw() wont work. Code: import java.awt.*; import java.awt.event.*; import javax.swing.*; public final class testclass extends JFrame { static JPanel p; Timer t; int x = 1; int y = 1; int xspeed = 1; int yspeed = 1; public testclass() { initComponents(); this.setBounds(100, 300, 500, 500); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); t.start(); this.add(p); } public void initComponents() { final ActionListener action = new

Java - repaint(x, y, w, h) doesn't call paintComponent? (with SSCCE)

二次信任 提交于 2019-12-01 20:35:27
I asked this before, but only theoretically, without an SSCCE. Now, I've created one, and the problem persists. I'd like to know why paintComponent is not called on repaint(x, y, w, h) , but is called on repaint() . Two classes: SANDBOX import java.awt.Dimension; import java.awt.FlowLayout; import javax.swing.JFrame; public class Sandbox { public static void main(String[] args) { JFrame f = new JFrame(); f.setMinimumSize(new Dimension(800, 600)); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(new FlowLayout()); // Add label f.getContentPane().add

Using paintComponent() to draw rectangle in JFrame

怎甘沉沦 提交于 2019-12-01 18:13:14
问题 I'm trying to create a program that draws shapes (a rectangle on the example below) using JPanel's paintComponent(), but I can't get it to work and can't spot what is wrong. The code is as follows: import javax.swing.*; import java.awt.*; public class RandomRec{ JFrame frame; public void go(){ frame = new JFrame(); frame.setSize(500,500); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DrawPanel panel = new DrawPanel(); } public static void main (String[] args){

Painting over the top of components in Swing?

浪子不回头ぞ 提交于 2019-12-01 17:45:59
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 college assignment: As you can see, the rectangle is behind the other panels. This is what I'm already doing