awt

SwingUtilities.invokeLater takes a Runnable and runs it on the EDT?

余生颓废 提交于 2019-12-06 01:29:43
问题 I am confused with the signature of SwingUtilities.invokeLater . It takes a Runnable object. Is it this Runnable object that is handed over to the Event Dispatch Thread? Why can't I directly call createAndShowGUI on the run method of EDT (if it is possible)? I have read articles on SO on how the EDT and invokeLater work, but I am confused with the Runnable object that is passed. SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); And what would happen if

Alt+Tab using Java Robot

余生颓废 提交于 2019-12-05 23:41:08
问题 I am trying to bring up the alt + tab menu with a Java Robot. When I call the alt_tab() method, I want to bring up the alt + tab menu and keep the menu up. I know this can be achieved using alt + ctrl + tab . So far I have tried the code below, and also just alt + tab without the control key. I am not sure why it's not bringing up the menu. All it does is emulate pressing the alt key. public void alt_tab() { Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent

Java - Convert Image to black and white - fails with bright colors

最后都变了- 提交于 2019-12-05 23:35:54
问题 I'm attempting to convert an image to black and white only (not grey scale). I've used this: BufferedImage blackAndWhiteImage = new BufferedImage( dWidth.intValue(), dHeight.intValue(), BufferedImage.TYPE_BYTE_BINARY); Graphics2D graphics = blackAndWhiteImage.createGraphics(); graphics.drawImage(colourImage, 0, 0, null); return blackAndWhiteImage; Everything fine, until I decided to try out brighter colors, like the Google logo for example: and it came out with this: Then I tried first to

Java custom Paint implementation performance issue

时间秒杀一切 提交于 2019-12-05 22:20:43
I'm using Java to create a game, and I'm using TexturePaint to texture areas in the background. Performance is fine using java.awt.TexturePaint, however, I want to have areas having an inherent rotation, so I tried implementing a custom Paint called OrientedTexturePaint: public class OrientableTexturePaint implements Paint { private TexturePaint texture; private float orientation; public OrientableTexturePaint(TexturePaint paint, float orientation) { texture = paint; this.orientation = HelperMethods.clampRadians((float)Math.toRadians(orientation)); } public PaintContext createContext

Rounded borders on a JPanel

依然范特西╮ 提交于 2019-12-05 21:58:29
What I've got here is a JPanel with a rounded border that is set up as such: panel.setBorder(new LineBorder(PanelColor, 5, true)); The problem is, in each of the corners there are 2 diagonal opaque lines going from the outer corner to the inner corner that is the length of the border. Whatever is behind the border shows through. Is there any way to get rid of these lines and make the entire border one solid color? Thanks! I'd attach a picture but I don't have enough rep to do so :P mKorbel Maybe here is a way to paint RoundedLineBorder; please be careful with constants for nice output to the

Create a Shape Object from Font Object in Java

余生颓废 提交于 2019-12-05 21:33:37
I have a font object and a String. I want to return a Shape Object that is a representation of the String. I have a whole bunch of other classes that will display the String and take care of it. I'm having trouble figuring out how to do this when I do not have a graphics/graphics2d object. Any Help? I have searched the net but had trouble finding helpful links. public class SpecializationOfTester extends ParentTester { private String str; private Font font; public SpecializationOfTester(String str, Font font) { this.font = font; this.str = str; } public Shape getShape() { Shape s; // // return

Java: create graphics without awt?

假装没事ソ 提交于 2019-12-05 21:17:49
问题 Is there any library out there to create graphics without using AWT? What I need is simple drawing functions (like to draw a line) and text drawing functions to create graphics in memory for a Google app engine application. App engine does not support AWT. Thanks! 回答1: Not unless you want to implement your own image class (say, a bitmap) and rendering algorithms for lines, shapes, images. If you have experience with computer graphics and rasterization, this may not be very hard, but otherwise

How to make a Round Rectangle JTextField?

微笑、不失礼 提交于 2019-12-05 19:46:34
I want to make a round rectangle JTextField. I write a sub class of AbstractBorder to realize it.But I run into some problems. My requirement is: What I get is: My code is : import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.Graphics; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import

Java swing 1.6 Textinput like firefox bar

江枫思渺然 提交于 2019-12-05 18:19:23
I would like to create a textwidget/component wich looks like the firefox address bar. I mean a Textfield wich allows me to place little Buttons inside the field (e.g. cancel/reload/...) I tried customizing a JLayeredPane, by creating a custom layout manager which maximizes the Textfield, and places the remainder from right to left. My problem is that this gave painting issues, I would not always see the items I added over the textfield. This might be Jython related, I try suppling java.lang.Integer(1) to the JLayeredPane.add . However the Layers are ordered exactly reverse to what the

Java GUI Rotation and Translation of Rectangle

泪湿孤枕 提交于 2019-12-05 16:57:37
I am trying to draw a rectangle in JPanel that would translate and then rotate itself to mimic the movement of a car. I have been able to make the rectangle translate and rotate, however it rotates around the origin of (0,0). I'm very pleased that I was able to have the rectangle move and rotate as I am very new to Java GUI, but I can not seem to get how to have the rectangle rotate around itself, because I experimented more with it, and when I initialized the rectangle and rotate it 45 degrees it's position was changed, which I would assume is the transform matrix that is appended from the