paintcomponent

Why .paintComponent() is defined on JComponent?

扶醉桌前 提交于 2019-12-20 06:49:15
问题 Sorry if my question doesn't adjust to the Stackoverflow requirements due to it is theorical but i don't know where else to ask. For the past few weeks i've been trying to understand better how the Swing API works and it's components in order to create my own custom components. I've read tons of tutorials, searched in here, i am neck-deep in Java's swing source code and frankly... my mind is a mess. As far as i understand, the swing components are composed of 3 parts: the model: where the

Leaving a trace while painting on a transparent JPanel

南笙酒味 提交于 2019-12-20 06:47:25
问题 I am relatively new graphics programmer in Java and here is a simple program I was trying. Here is the full code: broken into 3 classes. Class 1: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MyPanelB extends JPanel { int x=0; int y=0; public void paintComponent(Graphics g) { x=x+1; y=y+1; setOpaque(false); //setBackground(Color.cyan); g.setColor(Color.red); g.fillRect(x,y,x+1,y+1); } } Class 2: import javax.swing.*; import java.awt.*; import java.awt.event.*;

Java Graphics Checkout Simulation;

耗尽温柔 提交于 2019-12-20 06:27:59
问题 I am working on a project which is a Checkout Simulation. I have the code to make it work run but i am struggling to understand and implement how to add graphics(in my case a square) once a certain condition is true. For example i have made my code so that it goes through random numbers and if 2,4,6 or 8 has been randomly generated, someone will be added to the queue and the same goes for if they are even numbers 1 or 3, someone is removed from the queue. I basically just want to know how to

paintComponent not painting onto JPanel

﹥>﹥吖頭↗ 提交于 2019-12-20 06:07:02
问题 I am working on a homework assignment where I am supposed to make a program that allows you to paint custom shapes and lines, and move them around the screen. Originally I was using public void paint(g) to paint, but the shapes were flickering when I called repaint. Because of that I switched over to paintComponent(g) . However When I try to paint a shape nothing shows up. I believe this is because it isn't painting on top of the JPanel . The frame has 3 panels in a 3 row BorderLayout .

Post overriding the paint method of the components in java

时光毁灭记忆、已成空白 提交于 2019-12-20 05:49:23
问题 In java awt or swing when you want to change painting of some component you usually have to override the method paint(Graphics g) (in awt) or paintComponent(Graphics g) (in swing). This is usually (maybe allways - I'm not sure) done when you are creating the component for example: JPanel jPanel = new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; //... my implementation of paint, some transfromations, rotation, etc }

Java Swing draw lines with mouse click and drag

ⅰ亾dé卋堺 提交于 2019-12-20 05:36:34
问题 I want to bring back a question that was asked before: java draw line as the mouse is moved "I would like to add a feature to my application which allows the user to draw a straight line by clicking the mouse at the start location and releasing it at the end location. The line should move as the mouse moves until it is finally released; similar to the way that a line can be drawn using the Microsoft Paint application. How can implement this so that the line is repainted as it moves without

no repaint while resizing when using .setPaint(gradient)

爷,独闯天下 提交于 2019-12-20 04:08:07
问题 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

How do I create a JPanel with two images where only a part of the one below is shown on mouse over?

三世轮回 提交于 2019-12-19 11:49:09
问题 I am trying to create a button panel where the button that was clicked becomes 'differently colored'; i.e show the background image. p.s I only need this approach(with 2 images), and not anything else. Thanks ! Eg: public class TestPane extends JPanel { private BufferedImage imgUnclicked; private BufferedImage imgClicked; private Point mousePoint; public TestPane() { try { imgUnclicked = ImageIO.read(new File("C:\\Users\\Me\\Desktop\\tmp\\Uncolored.png")); imgClicked = ImageIO.read(new File(

repaint() in Java doesn't “re-paint” immediately?

人盡茶涼 提交于 2019-12-19 03:21:07
问题 I have a code like that: // In MyPanel.java public void paintComponent(Graphics g) { super.paintComponent(g); // Draw something mypanel_count++; } // In Test.java public void testLargeData() { while (notDone) { panel.repaint(); // do huge work test_count++; System.out.println("Test_count: " + test_count + ", MyPanel_count: " + mypanel_count); } } // Output !!! Test_count: 752, MyPanel_count: 23 Test_count: 753, MyPanel_count: 23 Test_count: 754, MyPanel_count: 23 Test_count: 755, MyPanel

How do i load images in Jframe java(eclipse)

£可爱£侵袭症+ 提交于 2019-12-18 18:04:31
问题 I have an paneel.java file wich looks like the following code: import java.awt.*; import javax.swing.*; public class Paneel extends JFrame { public static void main ( String [] args ) { // frame JFrame frame = new Paneel(); frame.setSize ( 1000, 1000 ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setTitle( "Remembory" ); frame.setVisible( true ); } class Gifpaneel extends JPanel{ private ImageIcon gif, animatedGif; public Gifpaneel() { gif = new ImageIcon( "test.gif" );