java-2d

How to generate events from graphics generated by Java2D

落爺英雄遲暮 提交于 2019-12-31 02:22:27
问题 I have made an Ellipse with the help of java.awt.geom.Ellipse2D Now, I want that whenever user clicks on that ellipse, an event is generated so that I can listen to that event and peform subsequent tasks based on the ellipse which generated that event. 回答1: Here is a simple example of an object drawing program that demonstrates click, drag and multiple selection. Also consider JGraph, which is a much more advanced library for graph visualization. 回答2: I'm going to assume this is a question

Stop Fullscreen Window from minimizing when JOptionPane.showMessageDialog?

你。 提交于 2019-12-31 01:14:11
问题 The Code private MainApp() /* Extends JFrame */{ DisplayMode displayMode = new DisplayMode(800, 600, 16, 75); ScreenManager.setFullScreenWindow(displayMode, this); } The Problem Whenever I call: JOptionPane.showMessageDialog(MainApp.getInstance(), "Test Message Box"); The Window minimizes for some reason, then I have to re-activate it. The Message Box shows after I re-activate the Window. The Question Is there any way to stop the Fullscreen Window from minimizing when I call the Message Box?

How do I specify fallback fonts in Java2D/Graphics2D

最后都变了- 提交于 2019-12-30 06:12:12
问题 I'm using g.drawString(str, x, y) to draw a String with a Graphics2D object g . The current font of g does not cover all the characters of str (I have e.g. Chinese chars in there). On Mac OS X, a fallback font seems to be automatically used, but not on Windows, where black square outlines appear instead of the wanted characters. Why is the behavior different depending on the platform? How do I specify a fallback font (or several fallback fonts) in case of missing characters? (For instance,

Java: Friendlier way to get an instance of FontMetrics

半世苍凉 提交于 2019-12-29 07:15:11
问题 Is there a friendlier way to get an instance of FontMetrics than FontMetrics fm = Graphics.getFontMetrics(Font); I hate this way because of the following example: If you want to create in a game a menu and you want all the menuitems in the center of the screen you need fontmetrics. But, mostly, menuitems are clickable. So I create an array of Rectangles and all the rectangles fits around the items, so when the mouse is pressed, I can simply use for (int i = 0; i < rects.length; i++) if (rects

How to disable the default painting behaviour of wheel scroll event on JScrollPane

谁说我不能喝 提交于 2019-12-29 05:37:39
问题 I recently purchased the book Filthy Rich Clients and i found it really useful and fun. Building on one example from the book i tried implementing a custom ScrollPane that displays a "shadow" on the bottom of its view over the component to be displayed. I ended up with the code below. It works but not perfectly. Specifically when i scroll the pane by dragging the scroll bar everything works ok and the painting is really smooth. But when i scroll with the mouse scroll the shadow flickers and i

about drawing a Polygon in java

泪湿孤枕 提交于 2019-12-29 01:33:11
问题 hi there i'm trying to improve myself about java2D and first of all i'm dealing with drawing polygons. However, i can not see the polygon on frame. I read some tutorials and examples but as i said i face with problems. here is the sample code of drawing a polygon; import java.awt.Color; import java.awt.Graphics; import java.awt.Polygon; import javax.swing.JFrame; public class jRisk extends JFrame { private JFrame mainMap; private Polygon poly; public jRisk(){ initComponents(); } private void

Java2D: Increase the line width

萝らか妹 提交于 2019-12-28 03:31:06
问题 I want to increase the Line2D width. I could not find any method to do that. Do I need to actually make a small rectangle for this purpose? 回答1: You should use setStroke to set a stroke of the Graphics2D object. The example at http://www.java2s.com gives you some code examples. The following code produces the image below: import java.awt.*; import java.awt.geom.Line2D; import javax.swing.*; public class FrameTest { public static void main(String[] args) { JFrame jf = new JFrame("Demo");

Java: mouse hit detection with overlapping JComponents

孤者浪人 提交于 2019-12-25 16:58:23
问题 I have a JPanel with null layout. On this panel I draw some custom JComponents as markers, little red rounds, and lines. When the line is not horizontal or vertical, the JComponent's "sensitive area" is a rectangle which has as hypotenuse the line itself. This excessive area often "steals" MouseEvents to the markers. How can I make MouseEvents "pass" to the covered objects, if the user is not clicking the real line? 回答1: The correct approach is that suggested by moonwave99. 1) Create and

Order of channels in BufferedImage?

陌路散爱 提交于 2019-12-25 13:46:30
问题 How do I find out the order of color channels in a BufferedImage (different types including alpha channels)? I need to know the order of R, G, and B parameters for operations like LookupOp (order of byte[][] in ByteLookupTable(int, byte[][])) or RescaleOp(float[], float[], hints). Is there a generic way to find the order from a given BufferedImage? I thought it should be in the ColorModel but I can't find it. I have used code like if (t == BufferedImage.TYPE_INT_ARGB) but there must be better

Order of channels in BufferedImage?

断了今生、忘了曾经 提交于 2019-12-25 13:44:09
问题 How do I find out the order of color channels in a BufferedImage (different types including alpha channels)? I need to know the order of R, G, and B parameters for operations like LookupOp (order of byte[][] in ByteLookupTable(int, byte[][])) or RescaleOp(float[], float[], hints). Is there a generic way to find the order from a given BufferedImage? I thought it should be in the ColorModel but I can't find it. I have used code like if (t == BufferedImage.TYPE_INT_ARGB) but there must be better