awt

How to display a mask in jtextfield?

夙愿已清 提交于 2019-12-20 03:51:05
问题 I want to display a mask in a text field. How can I do that? Is there any reusable java library to do that? I want to create a text field that only allow to enter eight digits (each digit should be either 0 or 1) E.g. 回答1: This will create a masked text field. When you press enter it will output what the user typed in. This uses JPasswordField. http://docs.oracle.com/javase/1.4.2/docs/api/javax/swing/JPasswordField.html import java.awt.*; import java.awt.event.*; import javax.swing.*; public

Drag rectangle on JFrame in Java

雨燕双飞 提交于 2019-12-20 03:50:28
问题 I want to draw rectangle based on mousedrag event. if user dragging the mouse, then the rectangle on the applet should increase or decrease basing on current mouse coordinates. i have the following code. in the following code i am using SelectionArea class which extends a canvas on which i am performing drawing operation. i am using image variable in this class for double buffering to reduce flickering and to save the applet's previous state(i.e drawing content of applet) but the code is

change buttons backgroundcolor in awt

时间秒杀一切 提交于 2019-12-20 03:39:06
问题 So i have a GUI program called Safe25. Basically, if you press the buttons in the right order which is "15032018" the program closes itself. If you input a correct number, lets say you press 1 at the start, the buttons should change their backgroundcolor to green like this: If you press a wrong button, the buttons should change their color to red. But the logic of my code is irrelevant for my problem. As i said, i want to change the buttons backgroundcolor like in the linked image. My problem

Error when declaring java.awt.FileDialog

流过昼夜 提交于 2019-12-20 03:12:40
问题 I'm trying to declare a java.awt.FileDialog in my code: FileDialog save = new FileDialog(null, "Save file", FileDialog.SAVE); But I get the following error in my console when I try to run my code: The constructor FileDialog(Frame, String, int) is ambiguous Anyone know what I am doing wrong? 回答1: There are 2 constructors for FileDialog with 3 arguments. Because you passed null as the first argument, the compiler cannot distinguish which constructor you want. FileDialog(Dialog parent, String

Java Swing Graphical Glitches Dealing with Transparency and Images

可紊 提交于 2019-12-20 03:05:23
问题 So I have this login form and I have a "user photo." I'm trying to make it so that when you hover the mouse over the photo area, a transparent label with a colored background will appear (to give the effect of "selecting the photo"). It looks like this: And once you move your mouse off it, it goes back to being "deselected." Now my problem is, if you hover your mouse over the login button first then move your mouse over the photo, a "ghost login button" appears. It looks like this: I don't

Toolkit.getDefaultToolkit().getLockingKeyState(…) never updates during program execution

柔情痞子 提交于 2019-12-20 02:17:11
问题 I have the problem that Toolkit.getDefaultToolkit().getLockingKeyState(...) never updates. It reports correctly the first time I query it, then when I change the state using keyboard, the change is never reflected. Is this by design (doesn't seem so in the API doc), a bug, or is there something with my code? Here's a short, self-contained example to demonstrate the issue: public class LockingStateIssue { public static void main(String[] args) { Timer timer = new Timer(); timer

In java, JFrame is Heavy Weight Component or Light Weight Component?

好久不见. 提交于 2019-12-20 02:09:27
问题 I Know Swing is considered lightweight because it is fully implemented in Java, without calling the native operating system for drawing the graphical user interface components. On the other hand, AWT (Abstract Window Toolkit) is heavyweight toolkit, as it merely makes calls to the operating system in order to produce its GUI components. But i heard that Swing is still based on AWT, and even Swing components must have at least one heavyweight container. In other words, JFrame, JApplet are not

Getting Height and Width of Image in Java without an ImageObserver

廉价感情. 提交于 2019-12-19 22:00:44
问题 I am trying to get the height and width of images (via a url) in Java without an ImageObserver. My current code is: public static void main(String[] args) throws IOException { // TODO Auto-generated method stub File xmlImages = new File("C:\\images.xml"); BufferedReader br = new BufferedReader(new FileReader(xmlImages)); File output = new File("C:\\images.csv"); BufferedWriter bw = new BufferedWriter(new FileWriter(output)); StringBuffer sb = new StringBuffer(); String line = null; String

Java bitmap font: blitting 1-bit image with different colors

给你一囗甜甜゛ 提交于 2019-12-19 19:40:26
问题 I'd like to implement a simple bitmap font drawing in Java AWT-based application. Application draws on a Graphics object, where I'd like to implement a simple algorithm: 1) Load a file (probably using ImageIO.read(new File(fileName)) ), which is 1-bit PNG that looks something like that: I.e. it's 16*16 (or 16*many, if I'd like to support Unicode) matrix of 8*8 characters. Black corresponds to background color, white corresponds to foreground. 2) Draw strings character-by-character, blitting

New Line \n is not working in JButton.setText(“fnord\nfoo”) ; [duplicate]

混江龙づ霸主 提交于 2019-12-19 16:55:25
问题 This question already has answers here : Word Wrap in JButtons (4 answers) Closed 4 years ago . On a JButton, I want to list information on multiple lines. I tried \n as a new line character but it didn't work. The following code: JButton.setText("fnord\nfoo") ; will be displayed as: fnordfoo How do I force a line break? 回答1: JButton accepts HTML, so for the line break to work use: JButton.setText("<html>fnord<br />foo</html>"); 来源: https://stackoverflow.com/questions/13503280/new-line-n-is