awt

How to use my trackpad for horizontal mousewheel scrolling in a Java AWT ScrollPane

≡放荡痞女 提交于 2019-12-22 05:18:20
问题 Like many modern mice and trackpads, my laptop supports vertical and horizontal scrolling. It's an addictive feature once you get used to it. I simply want my Java apps to support horizontal scrolling via the trackpad/mousewheel, but everywhere I search it seems that this is not possible in Java. I really want someone to tell me that I'm somehow doing it wrong, this feature is already requested behaviour: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6440198 The inability to do this

AffineTransform without transforming Stroke?

感情迁移 提交于 2019-12-22 03:20:08
问题 When using the Graphics2D scale() function with two different parameters (scaling by different ratios in x- and y-direction), everything drawn later on this Graphics2D object is scaled too. This has the strange effect that lines drawn in one direction are thicker than those in another direction. The following program produces this effect, it shows this window: public class StrokeExample extends JPanel { public void paintComponent(Graphics context) { super.paintComponent(context); Graphics2D g

Java: ImageIcon vs. Image difference

六眼飞鱼酱① 提交于 2019-12-22 03:20:00
问题 Could anyone explain to me in noob way what the difference is betweeen ImageIcon and Image classes/objects in Java? Thanks 回答1: Their nature and application is different. Image is an abstract superclass of all classes that represent graphical images. ImageIcon is an implementation of Icon interface that uses Image as its source. Edit: Think of an Image as something that could be rendered and an ImageIcon as something that will be rendered as an Icon when its paintIcon() method is called. Edit

Swing: How do I run a job from AWT thread, but after a window was layed out?

时光总嘲笑我的痴心妄想 提交于 2019-12-22 00:52:11
问题 My complete GUI runs inside the AWT thread, because I start the main window using SwingUtilities.invokeAndWait(...) . Now I have a JDialog which has just to display a JLabel , which indicates that a certain job is in progress, and close that dialog after the job was finished. The problem is: the label is not displayed. That job seems to be started before JDialog was fully layed-out. When I just let the dialog open without waiting for a job and closing, the label is displayed. The last thing

How to add imagepanel in jpanel inside Jframe?

二次信任 提交于 2019-12-22 00:00:06
问题 I'm trying to add an imagepanel which extends JPanel to another JPanel. Which is not working well for me. The paint function of image panel don't get invoked inside Jpanel but works fine in JFrame. Any ideas or help will be appreciated. import javax.swing.*; import java.awt.*; import java.awt.geom.RoundRectangle2D; import java.awt.image.BufferedImage; class ImagePanel extends JPanel { int g_h=10,g_w=10; int width=50,height=50; int cornerradius; Image castle; Dimension size; protected int x1

triple buffer heavy flickering

拟墨画扇 提交于 2019-12-21 23:12:08
问题 Shouldn't triple buffering and Canvas be an optimal solution for passive rendering? I've just wrote this java code that displays a circle. If I leave bufferstrategy to 3, it flickers so much. If I turn it down to 2 or 1 it's ok. Maybe I'm doing something wrong? public void run(){ while (running){ update(); draw(); } } public void update(){ } public void draw(){ BufferStrategy bs = getBufferStrategy(); if (bs==null){ createBufferStrategy(3); return; } Graphics g = bs.getDrawGraphics(); g

Scale tiny low-resolution app to larger screen size

喜欢而已 提交于 2019-12-21 22:30:35
问题 I am creating a retro arcade game in Java. The screen resolution for the game is 304 x 256, which I want to keep to preserve the retro characteristics of the game (visuals, animations, font blockiness, etc.). But when I render this on a large desktop display, it is too small, as one would expect. I'd like to be able to scale the window up say by a constant factor, without having to code the various paint(Graphics) methods to be knowledgeable about the fact that there's a scale-up. That is, I

Java app makes screen display unresponsive after 10 minutes of user idle time

匆匆过客 提交于 2019-12-21 16:59:03
问题 I've written a Java app that allows users to script mouse/keyboard input (JMacro, link not important, only for the curious). I personally use the application to automate character actions in an online game overnight while I sleep. Unfortunately, I keep coming back to the computer in the morning to find it unresponsive. Upon further testing, I'm finding that my application causes the computer to become unresponsive after about 10 minutes of user idle time (even if the application itself it

Unusual gaps while using JSeperator - Java

我与影子孤独终老i 提交于 2019-12-21 13:40:35
问题 I have been working on a Swing GUI and getting some unusual and unwanted gaps after adding JSeperator , Any idea how to remove them? Or any other option to how to achieve this nicely! Visual Description Gaps are apparent before JLabel "Speed" and after JSlider . Related Code control.setLayout(new BoxLayout(control, BoxLayout.X_AXIS)); ...another code omitted... control.add(orientation); //JLabel control.add(norm); //JRadioButton control.add(back); //JRadioButton control.add(new JSeparator

Java rotated text has reversed characters sequence

坚强是说给别人听的谎言 提交于 2019-12-21 12:28:07
问题 In a subclass of a JPanel I am doing this: public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; g2d.rotate(Math.toRadians(90.)); g2d.drawString(aString, 40, -40); } The letters are rotated correctly, but the second one is not in the expected position below the first (to its right, in the rotated space), but is above it (to its left), the third is above (to the left of) the second, etc. Changing the rotation angle to 45 degrees results in each