Questions tagged [paintcomponent]

paintComponent (JComponent.paintComponent(Graphics g)) is a method that Java Swing engine calls on JComponent, in order to draw it using the passed Graphics.

paintComponent is responsible for drawing contents of the JComponent, excluding border and possible children. Same as Canvas.paint, it may be overridden but is seldom called directly.

For custom Swing JComponent, it is overridden to paint a deeply custom content, in somewhat similar fashion as paint(Graphics) is overridden for Canvas (border and children as still painted as by default).

The passed parameter (Graphics) is actually Graphics2D and can be casted to use advanced features.

Standard Swing components delegate the call to the attached ComponentUI that paints the component by the rules of the current skin (look & fell).

1651 questions
6
votes
1 answer

.gif image doesn't moves on adding it to the JTabbed pane

I have a JFrame. In that i have two containers i.e two JPanel. one Panel holds a image. other holds a JButton. Then these two are added to JTabbedPane. My problem is on using a .gif image the image becomes static as any other normal .jpg image. Can…
user3320152
  • 113
  • 2
  • 7
6
votes
1 answer

Anti-aliased JLabel

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…
Joel Christophel
  • 2,604
  • 4
  • 30
  • 49
6
votes
2 answers

How do I rotate a graphics object, without changing it's location?

I got the following code: import java.awt.*; import javax.swing.*; public class GraphicPanel extends JPanel { public void paintComponent(Graphics g){ super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; …
user3150201
  • 1,901
  • 5
  • 26
  • 29
6
votes
2 answers

AffineTransform seeming to ignore component bounds

I have the following: public class ParametricEQView extends JPanel implements PluginView { private static final int BAND_WIDTH = 3; private static final int THROW_HEIGHT = 64; private static final int WIDTH = 128*BAND_WIDTH + 2*MARGIN; …
MattPutnam
  • 2,927
  • 2
  • 17
  • 23
6
votes
4 answers

How can i create a complex Button shape?

I have a frame with an image covering it, And i want that every time some one clicks on a different object in the image , it will act as a button and do something. The problem is , Is that those objects are not simple shapes, so i was thinking…
Dani Gilboa
  • 599
  • 4
  • 13
  • 30
6
votes
1 answer

Java Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

OK what I am trying to do here is create a game where the object/ball is controlled by clicking on the object with the mouse, pulling back the mouse (the distance the mouse is pulled back will determine the velocity of the object) and on releasing…
Phil
  • 61
  • 1
  • 1
  • 3
6
votes
2 answers

What do I need to do to replicate this component with gradient paint?

I attempted to replicate this component (at the bottom of the post), but I can't seem to get it to look nice. So I'm wondering, how do I replicate this gradient paint? Or if it isn't the gradient paint, what do I do to get similar results? My…
WilliamShatner
  • 926
  • 2
  • 12
  • 25
6
votes
3 answers

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

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) { …
Bood Carley
  • 538
  • 1
  • 4
  • 15
6
votes
2 answers

Clicking on a drawn object

I've got a class called Shape which inherits from JPanel. A number of sub-classes in turn extend the Shape classes, one for each type of shape. Each shape has its own overriden paint() method, which draws the respective shape. I would like to be…
Dot NET
  • 4,891
  • 13
  • 55
  • 98
6
votes
2 answers

How to make the background gradient of a JPanel

I want to know how to make background gradient which is in another JPanel. Many articles found in internet,but all of them had demostrated how to overide the paintComponent() of the JPanel not how to do for a jPanel which is inside it. I use…
Débora
  • 5,816
  • 28
  • 99
  • 171
6
votes
3 answers

Circular Progress Bar for Java Swing not working

i've discovered this test project from Oracle site because i want to add a circular progress bar in my project. I'm developing the application with Netbeans, and when i start the application, the JPanel where the circle should be.... disappaer. I've…
Deviling Master
  • 3,033
  • 5
  • 34
  • 59
6
votes
2 answers

How to draw an image over another image?

I have a Java project that's about traffic network simulation in a random city, I've managed to figure out a way to implement this project, so I divided each intersection into a section which is basically an extended JPanel class (named…
DZkid
  • 149
  • 1
  • 3
  • 9
5
votes
2 answers

Swing - paintComponent method not being called

i simply implemented class that inherits JPanel like below public class Orpanel extends JPanel { .... @Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; …
JayMuzie
  • 341
  • 1
  • 4
  • 16
5
votes
2 answers

Odd graphical bug: a copy of component A is painted on component B. HELP! (java)

I have made a simple paint program in which you can use a brush-tool to paint some different colors and erase (simply paint in white). It works fine, but I have a very strange graphical bug which causes the toolpanel and the last mouseovered…
tobes
  • 131
  • 2
5
votes
4 answers

how can i put a JButton on an image?

I am trying to fix a JFrame where there will be a background image and on the image JButtons which will do some commands. I try to do it without layout because i want to put small buttons in some specific locations on the JFrame but every time i do…
Eristikos
  • 485
  • 4
  • 9
  • 24