awt

Java - GetLockingState() won't update

荒凉一梦 提交于 2020-01-03 02:22:18
问题 Found bug Java Bug "CAPS" doesn't update. I want it to be actively checking the locking state but it only checks it once and stores true/false in "CAPS" but if you hit caps lock it doesn't change the boolean stored in CAPS. Thread capsCheck = new Thread(() -> { while (true) { boolean CAPS = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK); if (CAPS) { System.out.println("Caps enabled"); } else { System.out.println("Caps disabled"); } try { Thread.sleep(2000); } catch

run swing application without DSN creation

亡梦爱人 提交于 2020-01-03 01:42:06
问题 How to run the swing application without creating the DSN on the client I am working on a swing application in which i have to give the mdb database to the client with password protection , i dont want the need to create DSN on client side Is there any possible way to give the database path in the coding part rather than specifying the DSN name. because DSN creation is a complicated task for client. 回答1: USE below code to create your connection: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

GridBagLayout weighty alignment

我们两清 提交于 2020-01-02 11:30:02
问题 I am dinamically generating a layout which requires to use relative sizes, the only way I found to do it without using an external Java layout library is GridBagLayout's weightx and weighty. At this point it has been working exactly as I need with one small exception. When I have one column containing two JPanels with a space distribution of 66.6% and 33.3% respectively and then another column with 3 JPanels using 33.3% of the space each one of them, the 33.3% of the first column is not the

How do I center a java.awt.FileDialog on the screen

♀尐吖头ヾ 提交于 2020-01-02 08:03:44
问题 I have never been able to figure this one out; the usual suspects don't work. Given: FileDialog dlg=null; dlg=new FileDialog(owner,"Select File to Load",FileDialog.LOAD); dlg.setFile(null); dlg.setVisible(true); is there any way to get that dialog centered? A key point is that at setVisible(), the calling thread is blocked until the dialog is dismissed; and any positioning prior to that seems to be ignored. 回答1: The below solution works for SWT, probably it can do the trick for AWT as well...

setSize not influencing size of button

送分小仙女□ 提交于 2020-01-02 04:42:27
问题 I have a sample code : import java.awt.*; import javax.swing.*; import javax.swing.border.BevelBorder; public class AWT extends JFrame { public static void main(String[] args) { final JFrame frame = new JFrame(); frame.setPreferredSize(new Dimension(600, 450)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBackground(Color.green.darker()); Button btn_1 = new Button("Button 1"); btn_1.setBackground(Color.green.darker()); btn_1.setSize(40, 100); Button btn_2 = new Button(

Multiple Event Dispatch Threads

∥☆過路亽.° 提交于 2020-01-02 03:43:06
问题 I am new to Java Swing and my question is related to Event Queues and Dispatch threads. I read that it is possible to have multiple event queues , each per AppContext instance. Similarly does it mean each AppContext Event queue has its own event dispatch thread. 回答1: It is only possible to have one event dispatch thread as far as I'm aware. Apparently AppContext is not meant to be used by developers, although I'm not really familiar with it. 回答2: 1) basically you only needed to know if your

How to fire tab key event?

纵饮孤独 提交于 2020-01-02 02:14:08
问题 How do we fire a tab key pressed event deliberately in Java? I also want to know how to fire a Shift + tab key pressed event programmatically in Java. 回答1: The following example shows how to simulate mouse and key presses in Java using java.awt.Robot class. try { Robot robot = new Robot(); // Simulate a mouse click robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); // Simulate a key press robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_TAB);

How to output java full screen properly

走远了吗. 提交于 2020-01-02 00:58:05
问题 Now what I am doing in my program is that I am using setundecorated = true and MAXIMIZED_BOTH So it makes it go full screen and the display looks very nice, But the problem is that there are images (border) on the left and the right side of my screen and also a blue background. What happens is that in changing screens and resolutions these get disturbed and are not shown properly. Those grey patches come up again History: I have a java program which I wanted to always open in full screen; I

java.awt.Rectangle. intersection()

不问归期 提交于 2020-01-01 19:42:07
问题 I was developing an task when I decided to use java.awt.Rectangle to calculate the intersection between two rectangles. I realised that the output is different from what I expected. I'm not sure if I understood how this method works or not. For the values in the example here java.awt.Rectangle[x=0,y=10,width=5,height=8] java.awt.Rectangle[x=3,y=15,width=17,height=14] I expect the intersection to be java.awt.Rectangle[x=3,y=10,width=2,height=8] but the program prints java.awt.Rectangle[x=3,y

How can I implement java.awt.Composite efficiently?

无人久伴 提交于 2020-01-01 09:22:29
问题 Background: I need to be able to create imagery in "disabled" look. The commonly suggested approach is to convert images to grayscale and show the grayscaled image. The drawback is that it only works with images, making it cumbersome to show graphics where you do not have immediate access to an image in disabled state. Now I thought this could be done on the fly with java.awt.Composite (and then I would not need to know how for example an Icon is implemented to render it disabled). Only there