awt

Apple Retina Display Support in Java JDK 1.7 for AWT / Swing

穿精又带淫゛_ 提交于 2019-11-27 13:36:35
问题 I just became aware that AWT / Swing under Java JDK 1.7 (as of JDK 7u15) does not support Retina displays on Apple Macbook Pros. Netbeans, for example, is nearly unbearable to use for more than a few minutes running on a Retina display and using JDK 1.7. This has been somewhat addressed in a StackExchange question here, and quoting one specific post: Apple's Java 6 JRE will support HiDPI, however it is not currently supported by Oracle's Java 7 JRE. It also doesn't work under the latest dev

move component after drag and drop

守給你的承諾、 提交于 2019-11-27 09:53:11
I've seen code of drag and drop . Question1: how can we move image inside dropped panel (using mouse pointer) after image will be dropped. (destination of image, I want to be where where I release mouse. and then to change location too (using mouse will be better. or using buttons - but using mouse is better) Question2: how can I change location after dropping end? p.s I want here image to component. first I drag and drop component. then change location using mouse pointer (move it). here is code: import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.GridBagLayout; import

Is this the correct way of using Java 2D Graphics API?

感情迁移 提交于 2019-11-27 09:52:25
I'm creating a graphical front-end for a JBox2D simulation. The simulation runs incrementally, and in between the updates, the contents of the simulation are supposed to be drawn. Similar to a game except without input. I only need geometric primitives to draw a JBox2D simulation. This API seemed like the simplest choice, but its design is a bit confusing. Currently I have one class called Window extending JFrame , that contains as a member another class called Renderer . The Window class only initializes itself and provides an updateDisplay() method (that is called by the main loop), that

How can I check that JButton is pressed? If the isEnable() is not work?

一曲冷凌霜 提交于 2019-11-27 09:46:31
How can I check that JButton is pressed? I know that there is a method that its name is "isEnabled" So I try to write a code to test. this code have 2 Jbuttons which are "Add" Button and "Checkout" button. the code will show the "Add button is pressed" message when I press "Checkout" button after I press "Add" button but If the "Add" Button is not pressed before the "Checkout" Button is pressed, the code will show the "Add Button is not pressed" message. Here the code: final JButton btnAdd = new JButton("Add"); btnAdd.addActionListener(new ActionListener() { public void actionPerformed

How do I make a rectangle move across the screen with key bindings?

你离开我真会死。 提交于 2019-11-27 09:38:37
The game I'm trying to create is snake and so far I've figured out how to use paint(Graphics g) a bit of JPanel , mouse listener and now I'm trying to create a rectangle that will move across the screen and use key bindings or key listener, but I have no idea how I should go about this. Here's my code so far, it has 2 parts. The first part is called snake2 because if I don't know what I'm doing I make the same program with different things. Snake used frame, but Snake2 uses JPanel (looks better…) import java.awt.*; //required for MouseListener import java.awt.event.*; //requied for Graohics

Fahrenheit to Celsius conversion yields only 0.0 and -0.0

笑着哭i 提交于 2019-11-27 09:33:48
I'm on the 8th chapter (Methods, Constructors, and Fields) of my Java methods book and I'm having a problem with one of my exercises. The provided code is Temperature.java import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.text.DecimalFormat; public class Temperature extends JApplet implements ActionListener { private JTextField displayF, displayC; private static DecimalFormat displayFormat = new DecimalFormat("0.0"); public void init() { Container c = getContentPane(); c.setBackground(Color.white); c.setLayout(new GridLayout(2, 2, 10, 0)); c.add(new JLabel("

formatting text in jdialog box

无人久伴 提交于 2019-11-27 09:23:18
I have a JOptionPane: JOptionPane.showMessageDialog(null, text); The text is a sting: String text = "Hello world." What I want to do is change the color of the text, specifically a single word, lets say 'Hello'. SO what I've tried is: String t1 = "Hello"; String t2 = "world." Font serifFont = new Font("Serif", Font.BOLD, 12); AttributedString as = new AttributedString(t1); as.addAttribute(TextAttribute.FONT, serifFont); as.addAttribute(TextAttribute.FOREGROUND, Color.red); JOptionPane.showMessageDialog(null, as+t2); I'm not familiar with attributedtext() and this wont work. It does this: "java

zoom using mouse and graphics

我怕爱的太早我们不能终老 提交于 2019-11-27 09:21:10
I draw in my JComponent some curves, etc .. with Graphics G ( not 2D ). Now I want to use the scroll wheel of my mouse to zoom in and out. Any tracks ? I heard talk about a BuferredImage ? There are a few considerations you need to take into account... The end result will depend on what you want to achieve. If you are drawing curves using the Graphics2D API, it might be simpler to simply scale the coordinates each time the component is rendered. You will need to make sure that any changes in the scale are reflected in the preferred size of the component itself. You could also render the

JavaFX screencapture headless exception on OSX

◇◆丶佛笑我妖孽 提交于 2019-11-27 09:16:56
I'm converting my old java app from swing to javafx and I'm running into a problem. I'm using the following code to capture screenshots: public ScreenCapper() { ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); gs = ge.getScreenDevices(); try { robot = new Robot(gs[gs.length-1]); } catch (AWTException e) { LOGGER.getInstance().ERROR("Error creating screenshot robot instance!"); } } public Color capture() { Rectangle bounds; mode = gs[0].getDisplayMode(); bounds = new Rectangle(0, 0, mode.getWidth(), mode.getHeight()); //...... } This works fine when running the application under Windows.

Using addMouseListener() and paintComponent() for JPanel

佐手、 提交于 2019-11-27 09:09:42
This is a follow-up to my previous question. I've simplified things as much as I could, and it still doesn't work! Although the good thing I got around using getGraphics() . A detailed explanation on what goes wrong here is massively appreciated. My suspicion is that something's wrong with the the way I used addMouseListener() method here. EDIT completely rewrote the code. Still does not work properly though. import java.awt.Color; import java.awt.Graphics; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import javax.swing