paint

Get the text height including the font size and set that height

 ̄綄美尐妖づ 提交于 2019-12-30 06:33:14
问题 i have a text called Hello now i need to apply fontsize for this say 12 or 18 now as soon as we apply font to the text the text size increases. so now i need to get the text height including the font size using paint. i have tried with paint the following: String finalVal ="Hello"; Paint paint = new Paint(); paint.setTextSize(18); paint.setTypeface(Typeface.SANS_SERIF); paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.FILL); Rect result = new Rect(); // Measure the text rectangle to

How to stop repaint() flickering

China☆狼群 提交于 2019-12-29 09:30:11
问题 I am trying to make a program to java and i have the common problem with flickering. I have try many things to eliminate but all the same. while the oval that i paint is moving the japplet is flickering. i need your help to solve this problem. here is my code: import java.awt.Color; public class all extends JApplet implements Runnable { double x=0; double y=0; int m=0; int n=0; int f=30; int μ=0; Thread kinisi; JPanel panel; JFrame frame; private boolean running = false; private JTextField

Smooth window resizing in Windows (using Direct2D 1.1)?

与世无争的帅哥 提交于 2019-12-29 06:45:07
问题 It annoys me that the resizing of windows in Windows is not as "smooth" as it I'd like it to be (this is the case with Windows programs in general, not just my own. Visual Studio is a good example). It makes the OS and its programs feel "flimsy" and "cheap" (yes, I care about how programs and user interfaces feel , in the same way I care about the sound and feel of closing a car door. It's a reflection of build quality), which in my view affects the overall UX and ultimately the perception of

why is my code executing paintComponent(Graphics page) twice?

五迷三道 提交于 2019-12-29 01:58:06
问题 This is getting on my nerves and it probably something silly on my part but I can't figure out why my paintComponent is being called twice, if you run my code it outputs REPEAT? REPEAT? twice, I don't want it to do that.. So why does it do it and how can I fix it? import java.util.Random; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.*; public class Main extends JPanel { public Main() { /*code here*/ } public void paintComponent(Graphics page) { clear(page); /*code

Is there a “fill” function for arbitrary shapes in javafx?

空扰寡人 提交于 2019-12-29 01:28:35
问题 I need to know in which way I can color the following image (PNG) by using JavaFX. This image is currently included in a ImageView of JavaFX: I want to color region 1 blue, the second one red, and the last two purple. How can I do this in JavaFX? Isn't there some kind of function as in Windows Paint? (You know, the painting bucket that fills a certain area with a color between borders). 回答1: Suggested Approach You can use a flood fill algorithm. Sample Code import javafx.application

Regarding Android Paint drawing color

假如想象 提交于 2019-12-28 18:16:13
问题 DrawView.java public class DrawView extends View implements OnTouchListener { private Canvas mCanvas; private Path mPath; public Paint mPaint; ArrayList<Path> paths = new ArrayList<Path>(); private ArrayList<Path> undonePaths = new ArrayList<Path>(); private MaskFilter mEmboss; private MaskFilter mBlur; private Bitmap im; public DrawView(Context context) { super(context); setFocusable(true); setFocusableInTouchMode(true); this.setOnTouchListener(this); paths.clear(); undonePaths.clear();

Regarding Android Paint drawing color

坚强是说给别人听的谎言 提交于 2019-12-28 18:14:29
问题 DrawView.java public class DrawView extends View implements OnTouchListener { private Canvas mCanvas; private Path mPath; public Paint mPaint; ArrayList<Path> paths = new ArrayList<Path>(); private ArrayList<Path> undonePaths = new ArrayList<Path>(); private MaskFilter mEmboss; private MaskFilter mBlur; private Bitmap im; public DrawView(Context context) { super(context); setFocusable(true); setFocusableInTouchMode(true); this.setOnTouchListener(this); paths.clear(); undonePaths.clear();

How do I make a rectangle move across the screen with key bindings?

北慕城南 提交于 2019-12-28 03:12:18
问题 The game I'm trying to create is snake and so far I've figured out how to use paint(Graphics g) a bit of JPanel , mouse listener and now I'm trying to create a rectangle that will move across the screen and use key bindings or key listener, but I have no idea how I should go about this. Here's my code so far, it has 2 parts. The first part is called snake2 because if I don't know what I'm doing I make the same program with different things. Snake used frame, but Snake2 uses JPanel (looks

贪吃蛇系列之三——在窗口上绘制出简单的方形

断了今生、忘了曾经 提交于 2019-12-27 19:54:45
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 有了游戏的窗口了,接下来我们就开始在游戏的窗口中绘制出一些图形,由于我们做的是贪吃蛇嘛,就画一个方形吧,下面还是直接看代码: /** * 绘制界面的方法 */ @Override public void paint(Graphics g) { //设置画笔的颜色 g.setColor(Color.BLUE); //绘制出一个蓝色的正方形 g.fill3DRect(50, 50, 30, 30, true); } 我们得到的效果如下图: 我们既然要画图,就需要重写一个叫做paint(Graphics g)的方法,我们的java虚拟机将调用这个方法对窗口进行绘制,我们要实现的绘图逻辑呢就是在这里面来实现。这里要特别注意,是paint方法,不是print方法,很多同学不留心就会出错,到后面检查代码怎么都找不到错误的原因。 关于Graphics参数的理解。你可以理解为我们作画的画笔或者画布,这都是可以的。 关于g.fill3DRect(50, 50, 30, 30, true); 这句话的理解。这个方法就是我们让jvm帮我们绘制一个方形在窗口上,这个方法呢有5个参数,前两个参数是方块的起始横坐标。这里呢有一个常识就是,在我们的计算机绘图中,都是以窗口的左上角为坐标原点的,横坐标向右为正方向,纵坐标向下为正方向

Painting multiple JComponent on JPanel not working

一曲冷凌霜 提交于 2019-12-25 14:14:52
问题 I just don't get this. I want to add Highlight extends JComponent objects to a PdfPage extends JPanel but the Highlight components are simple not painted. I can see that their paint() and paintComponent() methods are getting called in correct order but they do not show. The only thing that fixes my problem is to add: for(Component component : this.getComponents()) { component.paint(g); } into the PdfPanel.paint() method but this is not how I want to do that. I want PdfPage extends JPanel to