awt

How to implement idle task in Java Swing

不问归期 提交于 2019-12-02 02:10:41
问题 I have a GUI app that is getting to be quite slow. I want to start introducing timing for various GUI tasks - however, many of our GUI actions trigger other actions which then "invoke later" to trigger other actions. Eventually, it all settles down and there's nothing more to do. At this time, I want to stop a timer and report how long that GUI "action" took. I figured the way to do this is to implement a method called invokeOnceIdle(Runnable task) . The method will execute the supplied task

change buttons backgroundcolor in awt

冷暖自知 提交于 2019-12-02 01:57:09
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 is that it changes the backgroundcolor of the frame instead like this The important line is 75, i

Java Swing Graphical Glitches Dealing with Transparency and Images

ε祈祈猫儿з 提交于 2019-12-02 01:56:42
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 know why this is happening. Can someone help? Here is the relevant code: package com.stats; public class

How to display a mask in jtextfield?

时间秒杀一切 提交于 2019-12-02 01:40:44
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. 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 class PasswordField1 extends JApplet implements ActionListener { /* Declaration */ private JPasswordField

how to draw rectangle on java applet using mouse drag event

末鹿安然 提交于 2019-12-02 01:37:40
i am using java. 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 [b]SelectionArea[/b] class which extends a canvas on which i am performing drawing operation. i am using [b]image[/b] 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 working fine if i draw first rectangle. if i start to draw second rectangle

Add transparent JPanel upon AWT Component to paint on

假装没事ソ 提交于 2019-12-02 01:17:30
I've got a Problem: In my Java application I've got an AWT Component (cannot change that one) that streams and shows an avi-file. Now I want to draw upon this movie and thought about putting a transparent JPanel above it and draw on that one. This does not work since I either see the avi-stream or the drawn lines but not both. I read somewhere that AWT does not support transparency of components - but the panel is a JPanel which is able to do so. Can someone please help me with this one - thanks in advance. The Mixing Light and Heavyweight Components article explains how this is handled only

Which is a better top level container for this design, JFrame with Jpanels, or JDesktop with JInternalFrames

↘锁芯ラ 提交于 2019-12-02 00:52:37
I'm a beginner with Swing and AWT, I'm looking to build a GUI using Netbeans. My GUI requires three areas, that I'm currently thinking of as JPanels on a JFrame. I require a "Drawing" panel that will listen for mouse input and draw Java2D shapes. The drawing panel will be anchored to the top left. The other two areas are a "Properties" scroll pane, and a "Controller" scroll pane. The controller pane will determine which drawn elements will be displayed via buttons, and the properties scroll pane will show details about any shape object that is clicked in the drawing pane (endpoints, color, etc

Printing an HTML file in java

爷,独闯天下 提交于 2019-12-01 23:42:52
I'm trying to print an HTML file my program generates, but it won't work. On Ubuntu, ".isSupported(Desktop.Action.PRINT)" return false, even though I have the gnome libraries installed, and on Windows 7, java throws the following exception: java.io.IOException: Failed to print file:/C:/Users/user/Documents/document.html. Error message: Unspecified error followed by a stacktrace. Below is the code, I'm using java.awt.Desktop. File doc = DocumentComposer.writeDocument(new File(System.getProperty("user.dir") + File.separator + "docs" + File.separator + docName + ".html"), case, data); if (Desktop

How to refresh the JComboBox data?

纵然是瞬间 提交于 2019-12-01 22:34:11
问题 I am having trouble refreshing the data inside the JComboBox . There is a button " Create " which has ActionListener , which adds the item to JComboBox . But the changes are not reflected in the GUI: I still don't see the new added item. repaint() doesn't help. Update: Here is a (almost) full GUI code: public class Main extends JFrame implements ActionListener { static Connection conn; static PreparedStatement ps = null; static ResultSet res; static Statement sta; private final static int

Why can't I get KeyEvent.VK_TAB when I use Key Binding for a JPanel

≯℡__Kan透↙ 提交于 2019-12-01 22:19:33
I will print related info if users focus on current window and press a key. However, it works for some keys like 'a' but not for 'tab'. Here is a simple demo: import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import javax.swing.AbstractAction; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.KeyStroke; public class KeyBindingTest { public static void main(String[] args) { KeyBindingTest test = new KeyBindingTest(); test.createUI(); } public void createUI(){ JFrame frame = new JFrame("KeyBinding