paint

Custom painting of JPanel

…衆ロ難τιáo~ 提交于 2019-12-10 18:02:04
问题 I'm not very good at this and I hope to get some help from people who understands the issue a lot more that I do. So here's the deal. In my application there is background JPanel with Image drawn over it. Then there is a small JPanel which I'm trying to create custom painting for. I wanted to have JPanel with rounded corners and semi-transparent background so I modified paintComponent method to fill semi-transparent rounded rectangle. But when I place components inside like say JComboBox, the

Java clears screen when calling paint method - how to avoid that?

放肆的年华 提交于 2019-12-10 15:58:33
问题 I'm trying to draw two lines in a Canvas in Java, calling two methods separately, but when I draw the second line, the first one disapears (Java clears the screen). How can I avoid that? I want to see the two lines. I've seen paint tutorials (how to make a program like the Paint on Windows) where the user uses the mouse to draw lines and when one line is drawn, the other do not disappear. They just call the paint method and it does not clear the screen. I'll be grateful if anyone can help me.

JScrollPane with transparent background and content

爷,独闯天下 提交于 2019-12-10 15:00:00
问题 In my app, I show a popup dialog to show a large list of cards. I display them as images in many JLabel components in a JPanel subclass. I then put that object in a JScrollPane to allow for horizontal scrolling through the cards. I want the unused space to be transparent with a dark background to show that what's behind it is disabled. I used setBackground(new Color(50, 50, 50, 200)) to achieve the look I want, but the content behind it does not redraw, so I get artifacting. Here's what it

GUI Java Program - Paint Program

老子叫甜甜 提交于 2019-12-10 14:13:45
问题 I've been trying to figure out what is wrong with my code here. The idea is to create a small Paint program and to have red, green, blue, and clear buttons. I have everything that I can think of for it to work, but can't figure out what is wrong with the code. The Program opens, and immediately closes. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Paint{ public static void main(String[] args){ gui g = new gui(); g.setVisible(true); } } public class gui extends

Java Swing JScrollPane line number glitch

十年热恋 提交于 2019-12-10 11:26:18
问题 I have a simple JEditorPane inside a JScrollPane that displays line numbers on the left side. It works great except when you move the window off screen and pull it back again, it looks the this when you stop dragging: any ideas? Should I need to be listening for a move/drag event and calling repaint/revalidate somewhere? Thought it might be something obvious, but here is some code. I am using the JSyntaxPane. public EditorPanel() { this.setLayout(new BorderLayout()); PythonSyntaxKit.initKit()

Qt catch pressed key

此生再无相见时 提交于 2019-12-10 10:43:26
问题 i think of to write primitive snake. i have window where program paints random lines. but i can't think up how to catch pressed key to change direction of painted line. class QUpdatingPathIte : public QGraphicsPathItem { void advance(int phase) { if (phase == 0) return; int x,y; int w,a,s,d; char c; // // HOW TO MAKE THIS HERE? (i had done early in console application) // but i can't do this in GUI , what should i do? scanf("%c",&c); if (c=='w') { x=-20; y=0; } else if (c=='s') { x=20; y=0; }

Animate color of Paint object

我怕爱的太早我们不能终老 提交于 2019-12-10 10:36:17
问题 I am trying to animate a Paint object in my custom view between colors. But the animation is not working. ObjectAnimator colorFade = ObjectAnimator.ofObject(mCirclePaint, "color", new ArgbEvaluator(), getColor(), 0xff000000); colorFade.setDuration(1500); colorFade.start(); invalidate(); I have previously set the paints color like this: mCirclePaint.setColor(Color.RED); UPDATE I don't think the Handler makes a difference to whether it animated or not. Even without the Handler I cannot animate

Override JButton paintComponent() doesn't work java

戏子无情 提交于 2019-12-10 10:18:27
问题 I wanted to paint my own version of JButton, so I have overridden the paintComponent() method, and drew a gradient roundRect. This works, but after that, I want to draw the String of the Button over it, and at compile-time, I got no error messages. But at runtime, I only see the roundRect, gradient, just as I intended it to be (I can click on it too), but the String is invisible... Here's my code: import javax.swing.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*;

Program to create shapes and show them on console

别来无恙 提交于 2019-12-10 09:52:34
问题 I was given small assignment as below . Can you please throw some light on how to implement this Write a simple structured program and simple oo program that implements display shape function. Your program should simply print out (to console ) the number if shapes and then ask each shape to display itself which will also cause a line of output to be generated to the console , one for each shape . It is perfectly OK for your main program to create a collection of shapes before on to sorting

android.graphics.Paint方法setXfermode (Xfermode x...

三世轮回 提交于 2019-12-10 04:35:08
用法:设置两张图片相交时的模式 例子: mPaint = new Paint(); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); 常见的Xfermode(SRC为原图,DST为目标图),把代码中的SRC_IN换成下图指定的模式就会出现对应的效果图。 Canvas canvas = new Canvas(Src); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(Dst, 0f, 0f, paint); 应用场景: Sheleve选选中某本书之后,出现聚光灯的效果,如下图所示: 来源: oschina 链接: https://my.oschina.net/u/105840/blog/40328