awt

Exception “java.awt.color.CMMException: Invalid image format” thrown when resizing certain images…why?

冷暖自知 提交于 2019-12-07 04:57:17
问题 After obtaining an image from db, when i try to resize it, by passing width using the below code public static BufferedImage resize(final byte[] pImageData, final int width, final int height, final int maxLength, final int minLength, final String imageSubType) throws Exception { InputStream is = null; BufferedImage resizeImageJpg = null; try { is = new ByteArrayInputStream(pImageData); BufferedImage originalImage = ImageIO.read(is); -------------------- } } The following exception is thrown

System.exit is not thread-safe on Linux?

两盒软妹~` 提交于 2019-12-07 03:56:31
问题 I've just switched from Oracle JDK 1.6, to Open JDK 1.7.0_03, and I've hit a rather remarkable deadlock on exit: java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) at java.lang.Thread.join(Thread.java:1258) - locked <0x8608dda0> (a sun.awt.X11.XToolkit$1$1) at java.lang.Thread.join(Thread.java:1332) at java.lang.ApplicationShutdownHooks.runHooks(ApplicationShutdownHooks.java:106) at java.lang.ApplicationShutdownHooks$1.run(ApplicationShutdownHooks.java

How do you read an image in Java when Toolkit.getDefaultToolkit() throws an AWTError?

▼魔方 西西 提交于 2019-12-07 03:22:38
问题 I am reading image files in Java using java.awt.Image img = Toolkit.getDefaultToolkit().createImage(filePath); On some systems this doesn't work, it instead throws an AWTError complaining about sun/awt/motif/MToolkit. How else can you create a java.awt.Image object from an image file? 回答1: I read images using ImageIO. Image i = ImageIO.read(InputStream in); The javadoc will offer more info as well. 回答2: There is several static methods in ImageIO that allow to read images from different

java add image to canvas

删除回忆录丶 提交于 2019-12-07 01:12:27
I'm trying to add a image to a java canvas. I'm using the "ImageIO.read" to get the image source. The problem i'm facing is that i don't know how to display it on the canvas after reading the image location. Also later i will need to load a different image(e.g. after a button pressed) how can i do this. The update (canvas.update) method needs a "Graphics" parameter instead of an image. Below you'll find my code simplified (i left out all code that's not relevant to the canvas issue.) public class MainWindow { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() {

KeyListener events apparently not firing in java applet

℡╲_俬逩灬. 提交于 2019-12-07 00:50:22
问题 I've just started learning to program applets, and java GUI in general, I'm attempting to make a simple game. At the moment, i have the main class (Game) and the player class (Player) i have the player drawing to the screen, but i'm struggling to get the key events to work, any help appreciated! The player image displays perfectly fine, but the position doesn't change when i hit a key at all. EDIT: wrong code posted for the player, updated Game.java: public class Game extends Applet { Player

Does java.awt.Robot.waitForIdle() wait for events to be dispatched?

荒凉一梦 提交于 2019-12-06 21:13:12
问题 I'm using java.awt.Robot for integration tests of my Swing application, but I'm having trouble running my actions in the correct order. How can I tell the thread that calls robot.mousePressed(...) to block until Swing is finished dispatching that event? Apparently, robot.setAutoWaitForIdle(true) does no good. Here's my demo. I expect the "robot finished!" message to always come after "Action finished blocking.", but instead it often happens too soon instead. import java.awt.AWTException;

Readding panel to layout after editing panel?

前提是你 提交于 2019-12-06 17:14:40
问题 What I'm trying to do is dynamicly edit a panel and readd it to the (Border)layout. The panel contains textfields and I want the user to be able to add or remove textfields to the panel. What I tried is the following: remove the panel from the layout, add another textfield to the panel, readd the panel to the layout. However this doesn't work ( nothing happened; only the panel was removed but not readded with the new textfield in it , so the area was just empty ). Even when I removed the

How to get real string height in Java?

爷,独闯天下 提交于 2019-12-06 17:14:14
问题 I'm using FontMetrics.getHeight() to get the height of the string, but it gives me a wrong value, cutting off the descenders of string characters. Is there a better function I can use? 回答1: The getStringBounds() method below is based on the GlyphVector for the current Graphics2D font, which works very well for one line string of text: public class StringBoundsPanel extends JPanel { public StringBoundsPanel() { setBackground(Color.white); setPreferredSize(new Dimension(400, 247)); } @Override

Get Click Count Mouse Listener on Touch Screen

萝らか妹 提交于 2019-12-06 16:33:49
Im running a simple JFrame with a JList. I encountered an issue just like this guy> Java getClickCount on touchscreen I know it has been posted already but there were no answers. jList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { System.out.println("MouseClick: "+e.getClickCount()); if (e.getClickCount() == 2) { Code below is working.. public class MainTest extends JPanel { public MainTest() { addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { System.out.println(me.getClickCount()); } }); } public static void main(String[] args) {

Repaint() is not being called in Java while loop

坚强是说给别人听的谎言 提交于 2019-12-06 16:28:26
I'm attempting to create a simple animation in Java that displays a blue ball moving horizontally part way across a 500 x 500 window. The ball is supposed to move at a rate of 1px/30ms. The problem is, is that the window is only being painted when the while loop exits and not during every iteration of the while loop as I intended. This results in the blue ball being painted in its final location. Could you please tell me what I'm doing wrong here? I've also tried executing this code on the EDT with the paintComponent() method and got the same result. In addition, as suggested by other posts, I