Questions tagged [awt]
The Abstract Window Toolkit (AWT) is Java's original platform-independent windowing, graphics, and user-interface widget toolkit.
6,585
questions
249
votes
9
answers
234k
views
What is the difference between Swing and AWT?
Can someone please explain me what's the difference between Swing and AWT?
Are there any cases where AWT is more useful/advised to use than swing or vice-versa?
227
votes
9
answers
755k
views
Java GUI frameworks. What to choose? Swing, SWT, AWT, SwingX, JGoodies, JavaFX, Apache Pivot? [closed]
There is quite a lot of gui frameworks out there for java, but what is recognized as today's framework of choice?
The following is my understanding of the different frameworks, please correct me if ...
138
votes
21
answers
240k
views
How to center a Window in Java?
What's the easiest way to centre a java.awt.Window, such as a JFrame or a JDialog?
96
votes
3
answers
95k
views
"Always on Top" Windows with Java
In Java, is there a way to have a window that is "Always on top" regardless if the user switches focus to another application? I've searched the web, and all of the solutions lean to some sort of JNI ...
96
votes
12
answers
166k
views
How to bring a window to the front?
We have a Java application that needs to be brought to the foreground when a telecontrol mechanism activates something in the application.
In order to get this, we have realized in the called method ...
88
votes
5
answers
6k
views
Swing GUI listeners without AWT
I am a starting Java developer, learning just from internet tutorials. I am learning full-screen GUI applications. I was told yesterday that I shouldn't use AWT in my programs because it is outdated. ...
83
votes
5
answers
102k
views
Copying to the clipboard in Java [duplicate]
I want to set the user's clipboard to a string in a Java console application. Any ideas?
70
votes
10
answers
539k
views
Setting background color for a JFrame
How do you set the background color for a JFrame?
69
votes
2
answers
44k
views
Java Event-Dispatching Thread explanation
I've recently started learning and exploring the basics of GUI programming in Java.
Having been programming for a while I have only done backend work or work and as a result the closest I've gotten ...
68
votes
3
answers
115k
views
Loading resources like images while running project distributed as JAR archive
I am having a error for my GUI. Trying to set title bar icon then be included in a Runnable JAR.
BufferedImage image = null;
try {
image = ImageIO.read(getClass().getClassLoader().getResource("...
57
votes
9
answers
104k
views
Java: using an image as a button
I would like to use an image as a button in Java, and I tried to do this:
BufferedImage buttonIcon = ImageIO.read(new File("buttonIconPath"));
button = new JButton(new ImageIcon(buttonIcon));
But ...
56
votes
5
answers
36k
views
SwingUtilities.invokeLater
My question is related to SwingUtilities.invokeLater. When should I use it? Do I have to use each time I need to update the GUI components? What does it exactly do? Is there an alternative to it since ...
55
votes
6
answers
169k
views
How to simulate a real mouse click using java?
I'm attempting to perform a mouse click in Java, to click something in an external program. To do this, I'm using java.awt.robot, and the following code:
Robot bot = new Robot();
int mask = ...
55
votes
5
answers
87k
views
What does SwingUtilities.invokeLater do? [duplicate]
What does SwingUtilities.invokeLater do? Is it just delaying the execution of a block of codes inside its run method? What is the difference between calling an action within the invokeLater function ...
47
votes
5
answers
243k
views
How to Change Font Size in drawString Java
How to make the font size bigger in g.drawString("Hello World",10,10); ?
44
votes
4
answers
3k
views
Is storing Graphics objects a good idea?
I'm currently in the process of writing a paint program in java, designed to have flexible and comprehensive functionalities. It stemmed from my final project, that I wrote overnight the day before. ...
41
votes
2
answers
25k
views
Calling awt Frame methods from subclass
This question is about Frames, Java and Processing.
This questions sounds pretty convoluted but its really not. I'll try keep this to a simple minimum. I'm creating a small ball in a maze game to get ...
37
votes
2
answers
21k
views
Java - FontMetrics without Graphics
How to get FontMetrics without use Graphics ? I want to get FontMetrics in constructor, now I do this way:
BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB);
FontMetrics fm = bi....
36
votes
6
answers
70k
views
Convert text content to Image
Is there out any Java library that allows converting text content to image files? I only know of ImageMagick (JMagick in this case) but I wouldn't like to install any external binaries (my app will be ...
36
votes
4
answers
94k
views
Border with rounded corners & transparency
The following screenshot shows a test of TextBubbleBorder1. I would like to make the corners of the component that are outside the rectangle to be entirely transparent & show whatever component ...
36
votes
5
answers
69k
views
Setting java.awt.headless=true programmatically
I'm trying to set java.awt.headless=true during the application startup but it appears like I'm too late and the non-headless mode has already started:
static {
System.setProperty("java.awt....
35
votes
2
answers
6k
views
Is it safe to construct Swing/AWT widgets NOT on the Event Dispatch Thread?
I've been integrating the Substance look and feel into my application and ran into several problems regarding it's internal EDT (Event Dispatch Thread) checking routines. Substance absolutely refuses ...
34
votes
10
answers
14k
views
Is Java Swing still in use? [closed]
I am planning on making a Java Swing application and was wondering if Swing is still used or if it has been replaced with something else.
Thanks in advance!
34
votes
6
answers
199k
views
Getting a HeadlessException: No X11 DISPLAY variable was set
Exception in thread "main" java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
at java.awt.GraphicsEnvironment....
31
votes
3
answers
47k
views
How can I convert an Icon to an Image
I'm trying to convert an Icon (javax.swing.Icon) to an Image (java.awt.Image) using this code:
private Image iconToImage(Icon icon)
{
if(icon instanceof ImageIcon)
{
return ((...
30
votes
3
answers
70k
views
Draw rectangle border thickness
Is it possible to do draw a rectangle with a given border thickness in an easy way?
29
votes
5
answers
51k
views
Get effective screen size from Java
I would like to get the effective screen size. That is: the size of the screen without the taskbar (or the equivalent on Linux/Mac).
I am currently using...
component.getGraphicsConfiguration()....
29
votes
4
answers
41k
views
NoClassDefFoundError: Could not initialize class sun.awt.X11FontManager
when we migrated from Oracle JDK-8 to Open JDK-11, Apache POI excel generation has issues
tried already -Djava.awt.headless=true
org.springframework.web.util.NestedServletException: Handler dispatch ...
28
votes
4
answers
52k
views
JFrame: get size without borders?
In Java, is it possible to get the Width and Height of the JFrame without the title and other borders?
frame.getWidth() and frame.getHeight()1 seems to return the width including the border.
Thanks.
28
votes
6
answers
63k
views
Turn an array of pixels into an Image object with Java's ImageIO?
I'm currently turning an array of pixel values (originally created with a java.awt.image.PixelGrabber object) into an Image object using the following code:
public Image getImageFromArray(int[] ...
28
votes
4
answers
14k
views
Copying to global clipboard does not work with Java in Ubuntu
The following code from a standalone application works in ubuntu:
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt....
27
votes
4
answers
51k
views
jTable right-click popup menu
I have a SQL database and I am working on a program that will allow me to add/delete/modify records. I already managed to add records I am working on editing/deleting them.
I want to display the ...
26
votes
3
answers
59k
views
How to use FileDialog?
I created an interface and I'd like to add a function that allows user to open a file. I'm using AWT. I don't understand how to use FileDialog. Can you please give me an example or a good link that ...
26
votes
4
answers
175k
views
Create GUI using Eclipse (Java) [duplicate]
Possible Duplicate:
Best GUI designer for eclipse?
Is there any Eclipse Plugin tool(s) who can help to create Graphical User Interface for (swing, awt or swt), because I'm tired of writing ...
25
votes
4
answers
39k
views
How to rotate text with Graphics2D in Java?
I want to rotate text on a JPanel using Graphics2D..
My code is this:
double paso=d.width/numeroBarras;
double alto=datos[i].valor;
Font fBarras=new Font("Serif", Font.PLAIN, 15);
...
25
votes
3
answers
6k
views
Safe to use Component.repaint() outside EDT?
I cannot find any official documentation saying that it is safe to call Component.repaint from another thread than the Event Dispatch Thread, the EDT.
Is this so? And where can I find some ...
25
votes
1
answer
11k
views
Collision detection with complex shapes
I am wanting to make a game that has each level loaded from an image.
I want to draw up the whole level in Photoshop, and then set it as the background and allow the player to walk over it.
I want ...
24
votes
9
answers
30k
views
Cannot load font in JRE 8
I cannot load a font from an S3 Inputstream in JRE 8. I do not have issue if a system is installed with JRE 7, JDK 7, or even JDK 8.
val fontInputStream = s3Client.getObject(bucketName, objectKey)....
24
votes
4
answers
12k
views
Apple Retina Display Support in Java JDK 1.7 for AWT / Swing
I just became aware that AWT / Swing under Java JDK 1.7 (as of JDK 7u15) does not support Retina displays on Apple Macbook Pros. Netbeans, for example, is nearly unbearable to use for more than a few ...
24
votes
4
answers
28k
views
Java and GUI - Where do ActionListeners belong according to MVC pattern?
I'm currently writing a template Java application and somehow, I'm not sure about where the ActionListeners belong if I wanted to cleanly follow the MVC pattern.
The example is Swing based, but it's ...
23
votes
8
answers
62k
views
Making a JScrollPane automatically scroll all the way down
I am trying to implement a JScrollPane with a JTextArea. The JTextArea is being appended to, and I want the JScrollPane to keep scrolling down as more text is added. How can this be achieved?
23
votes
9
answers
25k
views
What is java.awt.Component.getName() and setName() used for?
What is java.awt.Component.getName() used for? It always seems to be null in the applications I build with NetBeans. I'm thinking of storing some help text per component in it -- I don't want to use ...
23
votes
2
answers
41k
views
Using awt with android
I have a Java Swing application which draws diagrams. It uses Graphics2D calls and awt objects such as Rectangle etc.
At some point I might want to port this to Android. I understand that I can't use ...
22
votes
6
answers
28k
views
If Swing is deprecated, what is the alternative?
I heard that apparently Swing is being developed no longer. I like Swing and use it all the time.
What should I now be using instead?
22
votes
2
answers
50k
views
The import java.awt cannot be resolved
I have installed the Eclipse [Version: Photon Release (4.8.0)] and JDK 10 on a MacBookPro with macOS 10.13.5
When I write in my code: import java.awt.*;
I get the error:
The import java.awt ...
22
votes
5
answers
35k
views
What is the difference between listeners and adapters?
I'm trying to differentiate between listeners and adapters.
Are they pretty much the same but in listeners you have to implement all the methods in the interface, but with adapters you have an option ...
22
votes
2
answers
43k
views
AWT Window Close Listener/Event
I am sorry if this is a n00b question, but I have spent way too long for this once I create the Window listener, window event, and everything else, how do I specify what method to invoke? Here is my ...
22
votes
2
answers
36k
views
Add WebView control on Swing JFrame
I am working on Swing application mixed with JavaFX control.
I have created a JavaFX control (WebView) to browse HTML files. But I want
to know, how can I add this web view control on the ...
22
votes
8
answers
22k
views
Is there a simple way to compare BufferedImage instances?
I am working on part of a Java application that takes an image as a byte array, reads it into a java.awt.image.BufferedImage instance and passes it to a third-party library for processing.
For a unit ...
22
votes
5
answers
6k
views
Create an image from a non-visible AWT Component?
I'm trying to create an image (screen-shot) of a non-visible AWT component. I can't use the Robot classes' screen capture functionality because the component is not visible on the screen. Trying to ...