awt

Need a way to scale a font to fit a rectangle

一笑奈何 提交于 2019-12-03 12:00:31
I just wrote some code to scale a font to fit within (the length of) a rectangle. It starts at 18 width and iterates down until it fits. This seems horribly inefficient, but I can't find a non-looping way to do it. This line is for labels in a game grid that scales, so I can't see a work-around solution (wrapping, cutting off and extending past the rectangle are all unacceptable). It's actually pretty quick, I'm doing this for hundreds of rectangles and it's fast enough to just slow it down a touch. If nobody comes up with anything better, I'll just load the starting guess from a table (so

Adding fonts to Swing application and include in package

爱⌒轻易说出口 提交于 2019-12-03 10:41:48
I need to use custom fonts (ttf) in my Java Swing application. How do I add them to my package and use them? Mean while, I just install them in windows and then I use them, but I don't wish that the usage of the application will be so complicated, it`s not very convenient to tell the user to install fonts before using my application. You could load them via an InputStream : InputStream is = MyClass.class.getResourceAsStream("TestFont.ttf"); Font font = Font.createFont(Font.TRUETYPE_FONT, is); This loaded font has no predefined font settings so to use, you would have to do: Font sizedFont =

Graph visualization libraries for SWT/AWT

一笑奈何 提交于 2019-12-03 08:28:06
Is there a mature, solid open-source graph visualization library implementation for SWT or AWT (I am referring to sets of vertices connected with edges, not charts and diagrams)? Which one do you use/recommend? I saw Zest for SWT, but could not find a Maven repository for it. Thank you. I recommend Prefuse: http://prefuse.org/ Have a look at JUNG ( http://jung.sourceforge.net/ ) If you don't want to use Zest (which I prefer), there is still Draw2D : Draw2D Also, there is a good tutorial on this available here: Display a UML Diagram using Draw2D Finally, I found this Maven repository:

When you use Frame or JFrame in Java? [duplicate]

*爱你&永不变心* 提交于 2019-12-03 07:38:41
Possible Duplicate: What is the difference between swing and awt? I often see that JFrame is used a lots. But sometimes, I also see that programmer use Frame in their example. So could you tell me the advantages/disadvantages of them? Well let me break it up for you.............. Before jumping into Frame Vs JFrame, let me explain you about AWT and Swing. AWT : - It has a Platform Dependent Look and Feel . - So it uses the Native GUI components. - As AWT uses the peer components, its called as Heavy Weight Component . Swing : - It has a Platform Independent Look and Feel . - And its because it

Drawing a nice circle in Java

懵懂的女人 提交于 2019-12-03 07:35:35
I'm using Java Graphics and I keep getting "ugly" circles. Here's what my Java program makes And here's the same thing being made in Matlab I think it is clear that the Java one is not as "nice" looking as the Matlab one, particularly on the edges of the circle. Note that this has nothing to do with the resolution...these images are practically the same size. Also note that I am already setting rendering hints. Here's a stand alone with a Main function you can run to test this out. package test; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt

Java Robot class simulating human mouse movement

孤街醉人 提交于 2019-12-03 06:28:42
I am working on a project about remote control, send conrdinate x and y of cursor from client to server. But robot.mouseMove(x,y); will only move the cursor to the particular point without moving the cursor form origional point I have find this simple algorthim to simulate the continuing movement of mouse for (int i=0; i<100; i++){ int x = ((end_x * i)/100) + (start_x*(100-i)/100); int y = ((end_y * i)/100) + (start_y*(100-i)/100); robot.mouseMove(x,y); } But this algorthim still too simple, it just move from one point to other point slowly, which still unlike human behave. I have read some

How to Change Font Size in drawString Java

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 04:19:23
How to make the font size bigger in g.drawString("Hello World",10,10); ? John Snow g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize)); Where fontSize is a int. The API for drawString states that the x and y parameters are coordinates, and have nothing to do with the size of the text. Because you can't count on a particular font being available, a good approach is to derive a new font from the current font. This gives you the same family, weight, etc. just larger... Font currentFont = g.getFont(); Font newFont = currentFont.deriveFont(currentFont.getSize() * 1.4F); g.setFont(newFont); You

Get screen coordinates of a node in javaFX 8

流过昼夜 提交于 2019-12-03 03:42:45
I am developing a JavaFX application on Windows 8.1 64bit with 4GB of RAM with JDK version 8u45 64bit. I want to capture part of the screen using Robot but the problem is that I can't get the screen coordinates of the anchor pane that I want to capture and I don't want to use snapshot because the output quality is bad. Here is my code. I have seen the question in this link Getting the global coordinate of a Node in JavaFX and this one get real position of a node in javaFX and I tried every answer but nothing is working, the image shows different parts of the screen. private void capturePane()

java sending keystrokes using robot class

时光总嘲笑我的痴心妄想 提交于 2019-12-03 03:28:26
I know it's possible to send keystrokes in java using Robot Class , but is there any way to specify the target process when it's already started ? The Robot will send the keystrokes to whichever application window is on top. To send keystrokes to a specific target, you will want to set the target as the platform's foreground window first. Doing this may require native code such as that provided by JNI or (what I use) JNA. If you desire to send keystrokes to a background window, I believe that you cannot use Robot, that you will have to write native code. Of course all native code solutions

Find composite location on screen

前提是你 提交于 2019-12-03 03:13:14
I am implementing a on screen keyboard in Java for SWT and AWT. One important thing is to move the keyboard to a position where the selected text field can show and is not lying behind the on screen keyboard. For AWT i can detect the position of the current selected component with Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (owner == null) { return; } Point ownerLocation = owner.getLocationOnScreen(); Dimension ownerSize = owner.getSize(); How can i implement the same logic in SWT? I get the current selected widget by adding a focuslistener to