paintcomponent

Paint foreign component (i.e. belonging to a different frame's content pane) in another component

与世无争的帅哥 提交于 2019-12-04 19:29:44
Hallo all. I want to paint a foreign component (i.e. belonging to a different frame's content pane), lets call it frame B, inside a component in frame A. The problem is that when I paint the component it is painted also in the content pane of the frame A, also it flickers or all gets ugly when the frame is re-sized (i.e. painted few times inside the component, some blue squares are appearing, etc.). The issue becomes more visible if I try to, for example, scale or translate the foreign component before painting. After a while I sorted it, I think. But I do not feel good with this solution, for

Drawing an image in JScrollPane within scale

时间秒杀一切 提交于 2019-12-04 18:12:08
I have a scrollpane where load an image. I wont this image with her natural size, and if this image is too big, I wont activated the scrollbar, but this instruction g.drawImage(immagine, 0, 0, getWidth(), getHeight(), this); scaled image for placing in scrollpane. What can I do? Class Gui: import java.awt.*; import java.awt.event.*; import java.io.File; import javax.swing.*; public class Gui implements ActionListener { private JFrame frmEditor; private Mappa content; private JMenuItem mntmSfondo; private JScrollPane scrollabile; /** * Launch the application. */ public static void main(String[]

Painting pixels images in Java

空扰寡人 提交于 2019-12-04 11:28:29
问题 Which method is the best way to create a pixel image with java. Say, I want to create a pixel image with the dimensions 200x200 which are 40.000 pixels in total. How can I create a pixel from a random color and render it at a given position on a JFrame. I tried to create a own component which just creates pixel but it seems that this is not very performant if I create such a pixel a 250.000 times with a for-loop and add each instance to a JPanels layout. class Pixel extends JComponent {

Java Swing - Repaint() don't work correctly

微笑、不失礼 提交于 2019-12-04 06:06:09
问题 I take program from this topic. I try to edit points in real-time mode. I add MouseMotionListener to the constructor and write some basic functions to get near point to mouse and edit this point. When I get (x,y) points in the constructor, repaint() works strange. When I get (x,y) points in paintComponent , repaint() doesn't work at all. So, this are images with getting (x,y) in the constructor and in paintComponent . Where is my mistake? package simplegrapher2; import java.awt.BasicStroke;

paintComponent() in Java is not being called [duplicate]

大憨熊 提交于 2019-12-04 06:00:36
问题 This question already has answers here : Swing - paintComponent method not being called (2 answers) Closed 2 years ago . I am trying to draw a simple rectangle but I think the paintComponent method is not getting called. Here is the code for the class with main method: package painting; import java.awt.*; import javax.swing.*; public class Painting { public static void main(String[] args) { JFrame jf; jf = new JFrame("JUST DRAW A RECTANGLE"); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Drawing with paintComponent after value of Jbutton changed in another class

人走茶凉 提交于 2019-12-04 05:45:02
问题 I have a class named ControlsPanel. If I press a JButton (Start) in this class, the value of a boolean (isPressed) changes to true. In another class (CashRegistersPanel) I want to draw an Image, but only of the value of the boolean in the previous class is true. Of course the value of this boolean is false in the begining, so it doesn't draw anything. These are my two classes: public ControlsPanel(final ParametersPanel panel) { start = new JButton("Start"); stop = new JButton("Stop"); start

Why does swing draw simple component twice?

北战南征 提交于 2019-12-04 05:04:34
Here is simple example of drawing an oval. public class SwingPainter extends JFrame{ public SwingPainter() { super("Swing Painter"); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); getContentPane().add(new MySwingComponent()); setSize(200, 200); setVisible(true); } public static void main(String[] args) { new SwingPainter(); } class MySwingComponent extends JComponent { public void paintComponent(Graphics g) { System.out.println("paintComponent"); super.paintComponent(g); g.setColor(Color.red); g.fillOval(10, 10, 50, 50); } @Override protected void paintBorder(Graphics g) { System.out

Components on the JPanel doesn't show

假如想象 提交于 2019-12-04 02:15:35
问题 I created a JPanel and i modify it a bit. I change it's background to gradient color here is the class. public class JGradientPanel extends JPanel { private static final int N = 32; private Color color1, color2; public JGradientPanel(Color color1, Color color2) { this.setBorder(BorderFactory.createEmptyBorder(N, N, N, N)); this.color1 = color1; this.color2 = color2; } @Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; //Color color1 =

How to make a rectangle in Graphics in a transparent colour?

主宰稳场 提交于 2019-12-03 22:36:31
I'm trying to paint a rectangle on my application in a red shade but I need to make it sort of transparent so that the component under it will still show. However I still want that some colour will still show. The method where I'm drawing is the following: protected void paintComponent(Graphics g) { if (point != null) { int value = this.chooseColour(); // used to return how bright the red is needed if(value !=0){ Color myColour = new Color(255, value,value ); g.setColor(myColour); g.fillRect(point.x, point.y, this.width, this.height); } else{ Color myColour = new Color(value, 0,0 ); g.setColor

Trying to draw lines with JPanel

两盒软妹~` 提交于 2019-12-03 21:02:37
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; int drawCounter4 = 0; int x1 = 0; // cords change with the while statemetns int x2 = 0; int y1 = 0;