paint

Tickmark algorithm for a graph axis

為{幸葍}努か 提交于 2019-11-29 19:39:11
I'm looking for an algorithm that places tick marks on an axis, given a range to display, a width to display it in, and a function to measure a string width for a tick mark. For example, given that I need to display between 1e-6 and 5e-6 and a width to display in pixels, the algorithm would determine that I should put tickmarks (for example) at 1e-6, 2e-6, 3e-6, 4e-6, and 5e-6. Given a smaller width, it might decide that the optimal placement is only at the even positions, i.e. 2e-6 and 4e-6 (since putting more tickmarks would cause them to overlap). A smart algorithm would give preference to

What are the benefits to painting on a JPanel vs. JComponent?

烂漫一生 提交于 2019-11-29 18:23:14
问题 So in a recent answer, someone commented this (in regards to painting): "This is probably some kind of illness of 90% of Swing Programmers: When they make their own component, they always extend JPanel instead of JComponent. Why?" I'm still fairly new to programming, so I think it's too early to call myself a Swing programmer, as I have yet to find my niche. But overriding JPanel is just the way I was taught. So I set out to find the answer to the "Why?" question of the commenter. These are

Slow movement using paintComponent method

耗尽温柔 提交于 2019-11-29 18:18:34
I decided to re-write my game using Swing's painting technique paintComponent() method(someone on SO actually told me to use this method). I decided to use JPanel as the game's base instead of Canvas. My previous written game uses a Canvas but the game could not show up on my 64 bit desktop but could show up on my 32 bit labtop which is why this game had to be re-written. Problem now is, while the ship's movement works, the drawing seems awfully slow(unless it is my laptop problem?) compare to what I did before which was using AWT's double buffering drawing technique. I spend a whole day but

Reduce Padding Around Text in WinForms Button

一笑奈何 提交于 2019-11-29 18:12:57
问题 I have an application that is going to be used on a touch screen system, and it contains a number of buttons that are fairly large (~100px square). Each button will have between 1 and 4 lines of text (typically one word per line). Due to the large amount of padding in the button, I'm having to reduce the size of the text so that it becomes almost unreadable, however if I was able to reduce the internal padding so that the text would paint right up to the border, then I wouldn't have a problem

JTable returning null for Graphics?

ぃ、小莉子 提交于 2019-11-29 18:12:42
I'm trying to draw lines over my JTable using a Painter object that I've made, but for some reason table.getGraphics() returns null. Painter class: import java.awt.BasicStroke; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JTable; public class Painter extends JTable { public Painter(){ } public void paintSudokuLines(Graphics g){ paintComponent(g); } public void paintComponent(Graphics g){ super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setStroke(new BasicStroke(3)); g2.drawLine(0, 300, 400, 250); } } I'm calling the method with: private Painter paint =

Multiple problems regarding Java paint program while painting

牧云@^-^@ 提交于 2019-11-29 18:06:09
I have a Java paint program, and I've got two problems to do with it. Both problems are relatively simple, and just regard how the mouse input is handled and how the image uses colors. Here's a photo of the app: So here's my first problem: As you can see, by the look of the app, there's a spray of dots on the paint area. Each of those dots is a mouseclick. The program does not recognize when a user is holding down the mouse button, so you have to click individually. This is obviously counterproductive, user-unfriendly and unacceptable. Now, how I fix this, I'm not sure. I've tried using a

Java: Paint a histogram via fillRect()

可紊 提交于 2019-11-29 18:05:57
I like to make a histogram. With drawLine() , it's not really a problem for me, but when I try to do it with fillRect() the rectangles are going from top to bottom. I would like to paint the histogram looking similar to my histogram with drawLine() . Here is my code: public void paint(Graphics g) { super.paint(g); int height = getHeight(); int width = getWidth(); int x =10; haufigkeit=model.getMap(); for(int i = 1; i <= 45; i++) { int y; y = haufigkeit.get(i); Color color = new Color(0, 0, (int)(150 + Math.random() * 100)); g.setColor(color); // g.fillRect(x, 50, 10, y); // g.drawLine(x,

How do I stop my paint method form repeating twice?

混江龙づ霸主 提交于 2019-11-29 16:20:40
Here is the code for a dice game that I am working on that outputs the results to a window. The paint method repeats twice, which is not good for me because I want the dice to roll once and then move on to the next frame. Please someone help me with this problem. Thank you in advance. import java.awt.*; import java.util.Random; import javax.swing.*; public class Dice extends JApplet { public static int pause(int n) { try { Thread.sleep(n); } catch(InterruptedException e) { } return n; } public void Dice() { JApplet app = new Dice(); JFrame frame = new JFrame("Dice Game"); frame.setBounds(30,

Drawing line less than one pixel thick requires anti-aliasing in Android 4.2

 ̄綄美尐妖づ 提交于 2019-11-29 16:12:09
I'm trying to draw a very thin line (less than one pixel thick) in android. I'm using Paint blackThin = new Paint(); blackThin.setStrokeWidth(0.1f); blackThin.setColor(Color.BLACK); to initialize the paint object. This works fine in Android 2.2, but when I try it in 4.2 (also 4.1, I think - I tested that one briefly - I haven't tested any other versions other that 2.2, 4.1.2 and 4.2) the lines won't show up when I draw them. To make them show up in 4.2, it seems like I have to set the anti-aliasing flag to be true. (I tried that, and the lines showed up.) But I really don't want that, because

How to draw text with different stroke and fill colors?

吃可爱长大的小学妹 提交于 2019-11-29 16:09:21
问题 I want to display text as below in my app. I am using Paint class with style FILL_AND_STROKE to achieve this. But only one method setColor() is available to set the color. How do I set different stroke and fill colors? 回答1: Inside custom TextView (does not work in EditText): @Override public void onDraw(Canvas canvas) { final ColorStateList textColor = getTextColors(); TextPaint paint = this.getPaint(); paint.setStyle(Style.STROKE); paint.setStrokeJoin(Join.ROUND); paint.setStrokeMiter(10);