paintcomponent

Repainting a JPanel in a JScrollPane

左心房为你撑大大i 提交于 2019-12-23 12:14:58
问题 The project that I am working on is an inter-computer utility for playing table top games, and a key part of that is an interactive grid/map. Well I have built in functionality for custom map creation, and want the screen to be able to display very large maps, as well as very small maps. To this effect I have created a series of classes with which I can display a grid of any size. However what I would like to do is to put the JPanel which this is accomplished with into a JScrollPane, thereby

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

吃可爱长大的小学妹 提交于 2019-12-23 09:07:37
问题 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 attempt turned out very flat black compared to this component. Also it had the JFrame options (close, minimize, etc) and it didn't have a 'rounded' look to the components. I'm looking for someone who can improve what I have and explain where I went wrong

Java Graphics2D is Drawing One Pixel Off (Rounding error?)

梦想与她 提交于 2019-12-23 02:29:09
问题 I have been trying to make a program in Java using Graphics2D and PaintComponent. However, Java is not rounding some values correctly resulting in a few points being rendered a pixel different from where it supposed to be which gives an unclean image. You can see what I mean in the picture below. Here is my code. What can I change to fix this? Thank you! public void paintComponent( Graphics g ) { super.paintComponent( g ); g.setColor(Color.red); int orginX = getWidth()/2; int orginY =

When I paint a background image onto a JPanel, it behaves different under Windows than it does under Linux

不羁岁月 提交于 2019-12-23 02:01:21
问题 I'm developing a program for work (notice: I can not share complete code, as it is in large part protected work product, but I will share everything I can). In the application, I have JPanels that have background images applied to them. Some of these panels also have mouse listeners attached & my management wants there to be a visual clue that the panel can be clicked on to initiate an action. To that end, I've overlaid a transparent JPanel on top of the JPanel with the background image, and

Draw series of concentric circles with random settings

让人想犯罪 __ 提交于 2019-12-22 12:53:17
问题 I'm really stuck on how to go about programming this. Need to draw a series of 8 concentric circles using Java drawArc method with following conditions using import java.util.Random library Provide for starting the drawings at random location (i.e., the x-y cooridinate must be calculated randomly). Provide a random color for each circle Provide a random diameter for each circle My current code is able to get random random color for each circle but not clear how to meet other random conditions

This square I'm animating is leaving a trail behind it, can anyone work out why?

泄露秘密 提交于 2019-12-22 10:09:56
问题 Thanks for checking out this Question. I think I've just about scratched through my skull in frustration. So what I've got is a 'JFrame' containing a 'JPanel'. The 'JPanel' contains a little colored Square which is supposed to move X pixels whenever I click the window. Well, essentially everything behaves as it should, with one exception. When the blue square moves to the right, it leaves a trail of other squares behind it. It is not supposed to leave the trail, however, when I re-size the

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

杀马特。学长 韩版系。学妹 提交于 2019-12-21 06:58:05
问题 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

Java - rounded corner panel with compositing in paintComponent

回眸只為那壹抹淺笑 提交于 2019-12-20 09:57:07
问题 From the original question (below), I am now offering a bounty for the following: An AlphaComposite based solution for rounded corners. Please demonstrate with a JPanel . Corners must be completely transparent. Must be able to support JPG painting, but still have rounded corners Must not use setClip (or any clipping) Must have decent performance Hopefully someone picks this up quick, it seems easy. I will also award the bounty if there is a well-explained reason why this can never be done,

Java paintComponent tell if called again

一曲冷凌霜 提交于 2019-12-20 07:57:05
问题 Been Googling for a few days and I can't figure out how to tell if paintComponent is being called while I'm processing paintComponent. The process is long and complicated. If I have a second (or third) request to paint, I want to abort the current paint process and start over with the most recent request. 回答1: You can't; calls to paintComponent() are queued, blocking the EDT until completed. Use the approach shown in this AnimationTest to self-time your implementation on a typical target

How to draw 2d arrows with Java Swing?

大兔子大兔子 提交于 2019-12-20 07:55:32
问题 I'm trying to draw some rotatable arrows with Swing 2d, there are some sample code online, so I copied and combined them into one app, but there is something wrong with each of the 3 methods : 1st one doesn't rotate from it's center, the other 2 don't look correctly in the arrow head, can someone show me how to fix them ? import java.awt.*; import java.awt.geom.*; import javax.swing.*; import javax.swing.event.*; public class Arrow_Test extends JPanel implements ChangeListener { Path2D.Double