awt

Is it possible to have a MouseMotionListener listen to all system mouse motion events?

与世无争的帅哥 提交于 2019-12-01 17:52:35
问题 My boilerplate listener: class MyMouseMotionListener implements MouseMotionListener { public void mouseDragged(MouseEvent e) { System.out.println("Dragged..."); } public void mouseMoved(MouseEvent e) { System.out.println("Moved..."); }} Simple enough, but what do I add it to in order to listen to system-wide events? I've been researching are things like the GraphicsDevice and AccessibleContext subclasses -- they don't offer the addition of MouseMotionListeners directly but I was hoping they

Is it possible to have a MouseMotionListener listen to all system mouse motion events?

不羁岁月 提交于 2019-12-01 17:41:45
My boilerplate listener: class MyMouseMotionListener implements MouseMotionListener { public void mouseDragged(MouseEvent e) { System.out.println("Dragged..."); } public void mouseMoved(MouseEvent e) { System.out.println("Moved..."); }} Simple enough, but what do I add it to in order to listen to system-wide events? I've been researching are things like the GraphicsDevice and AccessibleContext subclasses -- they don't offer the addition of MouseMotionListeners directly but I was hoping they might give me some idea as to how I could implement this. Edit: This isn't at all event-based but I've

“Buffers have not been created” … whilst creating buffers

依然范特西╮ 提交于 2019-12-01 17:13:36
问题 I have (what I thought was) a straightforward BufferStrategy for a JFrame. It is created like so: // Buffer container.createBufferStrategy(2); strategy = container.getBufferStrategy(); However, occassionally I receive the following error (which points to the first line of the preceeding snippet as the offending item) : java.lang.IllegalStateException: Buffers have not been created This error is peculiar as it comes and goes - sometimes it is triggered, sometimes not. I suspect this means it's

New Line \\n is not working in JButton.setText(“fnord\\nfoo”) ; [duplicate]

别说谁变了你拦得住时间么 提交于 2019-12-01 16:51:53
This question already has an answer here: Word Wrap in JButtons 4 answers On a JButton, I want to list information on multiple lines. I tried \n as a new line character but it didn't work. The following code: JButton.setText("fnord\nfoo") ; will be displayed as: fnordfoo How do I force a line break? JButton accepts HTML, so for the line break to work use: JButton.setText("<html>fnord<br />foo</html>"); 来源: https://stackoverflow.com/questions/13503280/new-line-n-is-not-working-in-jbutton-settextfnord-nfoo

Printing a 1800 x 1200 image on 4 x 6 paper using Java

夙愿已清 提交于 2019-12-01 16:24:15
问题 I need to print a 1800 x 1200 pixels, 300 dpi image on 4" x 6" paper (also known as 4r) What I have Tried I have created a PrintRequestAttributeSet which takes care of my PrintableArea (4 x 6), Printer print DPI , Orientation . I have attached a MCVE at the bottom. Problem While the code works, and I get a PageFormat with the following attributes(for my printer) : x= 12.0 y= 12.32 w= 276.0 h= 419.67 The width and height are little less, because my printer doesn't support Zero Margin . ( This

What's the use case of a protected method in a final class in Java?

孤人 提交于 2019-12-01 16:03:40
问题 Consider this code from the official OpenJDK source of java.awt.font.TextLayout : public final class TextLayout { /* ... */ protected void handleJustify(float justificationWidth) { // never called } } What's the use case here and why might it make sense to write code like that in general? 回答1: protected members can still be accessed by code from the same package. My guess is that the class used to be non-final in some earlier (perhaps not even public) version, was then made final, and the

How to draw an outline around text in AWT?

女生的网名这么多〃 提交于 2019-12-01 15:43:44
How can I draw an outline around any text in AWT, something similar to this picture? mKorbel two examples Font and AffineTransform Font, TextLayout and AffineTransform output from this paint would be the BufferedImage , for AWT Components use method paint() , for Swing JComponents is there paintComponet() Also, from code linked in a comment: Try the following: public void paintTextWithOutline(Graphics g) { String text = "some text"; Color outlineColor = Color.white; Color fillColor = Color.black; BasicStroke outlineStroke = new BasicStroke(2.0f); if (g instanceof Graphics2D) { Graphics2D g2 =

Fastest way to create a Java message dialog (swing/awt/other)?

可紊 提交于 2019-12-01 15:22:00
I'm creating a Java application that will do some processing then needs to display a message to give the user feedback. However, it appears to be incredibly slow - taking over two seconds to return. I stripped the source down to the apparent culprit, and here is the code used: package SwingPlay; import javax.swing.JFrame; public class Dialog { public static void main( String[] args ) { JFrame frame = new JFrame( "DialogDemo" ); } } I'm executing this from the command line with: java -classpath . SwingPlay.Dialog As you can see - I'm doing nothing but create a JFrame, not even displaying it. In

JAVA can't paint onto JFrame from within another class

为君一笑 提交于 2019-12-01 14:38:54
I am aware this is my error. My question is why isn't this working what am i missing i can call this is i put it a method instead of a class so i am assuming theirs something wrong with the third class? Class 1: package assignment.pkg1.java; import java.awt.Color; import javax.swing.JFrame; public class JVMVeiwer { /** * @param args the command line arguments */ public static void main(String[] args) { final int FRAME_WIDTH = 1000; // Frame Width final int FRAME_HEIGHT = 800; // Frame Height JFrame frame = new JFrame(); frame.setSize(FRAME_WIDTH, FRAME_HEIGHT); //Sets Frame Size frame

How to draw an outline around text in AWT?

走远了吗. 提交于 2019-12-01 14:36:55
问题 How can I draw an outline around any text in AWT, something similar to this picture? 回答1: two examples Font and AffineTransform Font, TextLayout and AffineTransform output from this paint would be the BufferedImage , for AWT Components use method paint() , for Swing JComponents is there paintComponet() Also, from code linked in a comment: 回答2: Try the following: public void paintTextWithOutline(Graphics g) { String text = "some text"; Color outlineColor = Color.white; Color fillColor = Color