awt

Creating a dot/pixel outside of a JFrame, any location on the screen

半世苍凉 提交于 2019-11-27 07:26:39
问题 I would like the be able to display points on the screen for my Java application. At some point I want to be able to let the user move the points and drag them around. Currently I am having trouble trying to draw a single dot/pixel on the screen outside of a JFrame. Any ways to draw outside of your JFrame area? 回答1: You might create a full screen JFrame with full transparency, and draw to a panel or image on that. Much like this, which uses a custom panel to create a 'flashlight' effect for

Space button size on my layout keyboard won't resize

对着背影说爱祢 提交于 2019-11-27 07:23:17
问题 I am working on a typing app which includes the a keyboard but I have found a bit hard to re-size the space button to make it wider than the other buttons.. This is the way I am displaying and organizing my layout.. I can resize the whole buttons but its NOT what I want.. the whole point is to be resize just the space bar.. :) import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionListener;

How to request focus synchronously in Swing?

牧云@^-^@ 提交于 2019-11-27 07:13:17
问题 When I call component.requestFocusInWindow() , Swing enqueues asynchronous FOCUS_GAINED and FOCUS_LOST events rather than synchronously transferring focus. As a workaround, it appears that DefaultKeyboardFocusManager is trying to simulate synchronously switching focus by delaying the dispatch of keyboard events until focus events have finished dispatching. But it appears that this isn’t working properly. Question: Is there any way to change focus synchronously in Swing? Is

drawing simple rectangles on a Jframe in java

折月煮酒 提交于 2019-11-27 06:58:44
问题 I am extending JFrame like this: public GameFrame() { this.setBounds(30, 30, 500, 500); this.setDefaultCloseOperation(EXIT_ON_CLOSE); initializeSquares(); } private void initializeSquares(){ for(int i = 0; i < 5; i++){ this.getContentPane().add(new Square(i*10, i*10, 100, 100)); } this.setVisible(true); } However, only one square is being drawn on the screen, does anybody know why? also My Square class looks like this: private int x; private int y; private int width; private int height;

Double Buffering with awt

痴心易碎 提交于 2019-11-27 06:53:48
问题 Is double buffering (in java) possible with awt? Currently, I'm aware that swing should not be used with awt, so I can't use BufferStrategy and whatnot (I already have some code written in awt that I don't want to rewrite in swing). If double buffering is possible with awt, do I have to write the buffer by hand? Unlike swing, awt doesn't seem to have the same built-in double buffering capability. If I do have to write the code by hand, is there a good tutorial to look at? Or is it just easier

How to make a line curve through points

半世苍凉 提交于 2019-11-27 06:45:15
问题 I'm looking for a way to make a line curve through a number of points. It would be preferable to use 3 points although I've considered that in order to give context to the angle of the line entering a point more may be needed to give context to the curve so to speak. In general a start point P1, a control point P2 and an end point P3, the line should curve to P2 from P1 and then curve from P2 to P3. In fact here is a perfect example of the effect I would like to achieve: If I could do this I

Convert text content to Image

ぃ、小莉子 提交于 2019-11-27 06:21:10
Is there out any Java library that allows converting text content to image files? I only know of ImageMagick (JMagick in this case) but I wouldn't like to install any external binaries (my app will be deployed as a .war file in a Tomcat server so I don't want any other dependencies more than Java). For example, from the string "Hello", I would like to generate this simple image: The Graphics 2D API should be capable of achieving what you need. It has some complex text handling capabilities as well. import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt

Why does a Latin-characters-only Java font claim to support Asian characters, even though it does not?

两盒软妹~` 提交于 2019-11-27 06:07:59
问题 When rendering a chart with JFreeChart, I noticed a layout problem when the chart's category labels included Japanese characters. Although the text is rendered with the correct glyphs, the text was positioned in the wrong location, presumably because the font metrics were wrong. The chart was originally configured to use the Source Sans Pro Regular font for that text, which supports only Latin character sets. The obvious solution is to bundle an actual Japanese .TTF font and ask JFreeChart to

Safe to use Component.repaint() outside EDT?

送分小仙女□ 提交于 2019-11-27 05:46:25
问题 I cannot find any official documentation saying that it is safe to call Component.repaint from another thread than the Event Dispatch Thread, the EDT. Is this so? And where can I find some documentation/code? 回答1: Here is a quote from an official page stating that: The following JComponent methods are safe to call from any thread: repaint() , revalidate() , and invalidate() . The repaint() and revalidate() methods queue requests for the event-dispatching thread to call paint() and validate()

AffineTransform.rotate() - how do I xlate, rotate, and scale at the same time?

早过忘川 提交于 2019-11-27 05:39:23
I have the following code which does (the first part of) what I want drawing a chessboard with some pieces on it. Image pieceImage = getImage(currentPiece); int pieceHeight = pieceImage.getHeight(null); double scale = (double)side/(double)pieceHeight; AffineTransform transform = new AffineTransform(); transform.setToTranslation(xPos, yPos); transform.scale(scale, scale); realGraphics.drawImage(pieceImage, transform, this); that is, it gets a chess piece's image and the image's height, it translates the drawing of that image to the square the piece is on and scales the image to the size of the