awt

Set property for all child components

I've never used Java AWT before and now I've got a piece of code that displays a JFrame and sets the font property for all child components to the same value. I'd like to set the property in one place only. How can I do this? In .NET/WinForms, child controls inherit from their parent controls, thus it would be enough to set the font for...

How are Swing components internally created, laid out, repainted, notified of events, ...?

Hello! I wonder if there's a good documentation (or a (viewable) ebook) about the lifecycle of Swing components. Is "lifecycle" the correct term, anyway? I hope to find answers to question such as: How, when, in which order painting methods are called? How, when, which events are called by whom? What is the exact sequence of method ...

How to enter text in a cross-platform way with the AWT Robot?

The AWT Robot lets you send key press and release events given the keycode of the key you want to press. But the combination of key(s) you need to use to type a character depends on the input locale (e.g. the keyboard layout). We've worked around that by writing our own Keyboard abstraction that maps characters to AWTKeyStrokes and l...

setBorder method for JLabel causing paint problem

I have a custom class that extends JLabel. For specific instances of that class, I want to add some spacing to the text on the left side. I need the spacing as I'm setting the background of this JLabel and I don't want the text to bump up right next to the edge of the colored background. I fished around quite a bit and implemented thi...

java.awt.Frame.setBackground() not working in OS X

I'm trying to iron out some UI rendering bugs in my java applet in OS X, and I've hit one that I can't figure out. All the windows that we open that extend java.awt.Frame seem to ignore the setBackground() calls, and instead use the OS X default (brushed metal or gray gradient, depending on the OS version). Anything we open that extend...

How do I get a Raster from an Image in java?

I'm trying to load a gif image from a url into a java.util.image.Raster so I can manipulate it. The only method for loading and decompressing an image I could find was Toolkit.getImage, which returns a java.awt.Image. I need to turn that into a Raster so I can work with it. Suggestions? ...

Swing: How to make non-rectangular windows with soft borders?

Hello! How could I make non-rectangular windows with soft borders in Java? Soft borders (also known as soft clipping) are borders without aliasing artifacts. I searched the web a lot and found several posts about translucent and/or non-rectangular windows. The topic "soft border" is confusing. It seems that the information I found dea...

Why do radio buttons render improperly in a java.awt.Dialog on the Mac when the dialog is modal?

I'm in the process of testing my Java application on the Mac and I've run into a very strange issue. Checkboxes that appear in a modal Dialog render incorrectly, though non-modal Dialogs work fine. For example, say I have a window with 2 radio buttons. When the dialog opens the first one is selected. When I click on the second button...

key events

hi... i m using the keyboard event on Robot Objects.... but each time i have to specify the keys individually....like Robot r=new Robot(); r.KeyPress(KeyEvent.VK_A); r.KeyPress(KeyEvent.VK_B); r.KeyPress(KeyEvent.VK_C); r.KeyPress(KeyEvent.VK_D); is there any technique to get/recognize eachand every keys....not by specifying them ind...

How do I use more than two colors using and AWT hardware cursor?

I want to use a hardware cursor for a computer game I am making, AWT allows me to do so, and specify an image to use, however it only accepts 2 colours and transparency, which is fairly limiting. I'm fairly certain that it's possible to use a greater colour depth on most current systems, is there any way to achieve that in AWT? What ab...

Does anyone know why Java AWT cursors get wrong hotspots on Vista?

When I'm create custom AWT cursors, it seems that they get the wrong hotspot when running on Windows Vista or Windows 7 -- the hotspot is offset by a few pixels to the right and down. On Windows XP and on Linux with X.org, I'm not seeing the problem at all. Is this a bug, or am I just doing something weird? I'm creating the cursors with...

Handling \n in LineBreakMeasurer

There are thousand articles how to use LineBreakMeasurer to draw multi-line text but there is none about drawing multi-line text taking into account also \n(when you want to force a new line at a specific position in text and not only when the right - or left - margin ends). The secret seems to lie in BreakIterator, but I couldn't find ...

What causes a NullPointerException in the AWT-EventQueue-0 thread

I'm trying to do something to track down the problem, but there's not much I can do until paintContents, and everything there looks good through my debugger, but I'll double check to make sure I didn't miss anything. At the very least, I would like to know how to silently handle these (such as catching them and being able to output a mea...

Drag rectangle on JFrame in 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 SelectionArea class which extends a canvas on which i am performing drawing operation. i am using ima...

How can I do full screen in Java on OSX

I've been trying and failing to use the java full screen mode on the primary display of an OSX system. Whatever I've tried I can't seem to get rid of the 'apple' menu bar from the top of the display. I really need to paint over the entire screen. Can anyone tell me how to get rid of the menu? I've attached an example class which exhi...

Problems with swing components and awt events

I seem to be having problems with my java gui code, and I have no idea why it's not working. What needs to happen is when the mouse is clicked on the panel or frame - for now lets just say panel; as this is just a test eventually this code will be implemented for another gui component, but I'd like to get this working first - the popup ...

Transparent Swing Windows

I have a little JWindow with a logo on it that users can drag stuff to. I develop my application mainly on OS X. To get a transparent window i use setBackground(new Color(0,0,0,0)); On a mac this works beautifully but i can't get the same effect on windows. Is there any way to get a transparent window without using 1.6 specific featur...

[JavaFX] AWT bridge's "Hello World"

Hi everyone, I've heard about the JavaFX->AWT bridge (or hack) for a moment now. But examples I find are quite fuzzy or blur to me. So, if anyone knows an "Hello World" example for this bridge I'd be really interested ! (Just to be clear I don't need a way to embed a Swing component in a JFX animation or to launch a JFX from a Swing b...

What is the AWT equivalent to JFrame.setDefaultCloseOperation?

We are using the setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) method of JFrame. I want to support the native look and feel, and thus I have to use AWT instead of Swing. So what is the AWT method equivalent to setDefaultCloseOperation? Am I correct in thinking that in order to support the native look and feel we should use AWT instea...

Hosting ActiveX controls on a Java AWT Frame?

Is there a way to display a Flash or Adobe Reader ActiveX control in a Java AWT frame? I'm porting a large old J++ application to standard Java and it needs to host a certain ActiveX control on an AWT frame. Is this possible? I looked at the JACOB (Java to COM Bridge) project and it doesn't appear to support ActiveX objects that draw...