Questions tagged [awt]

The Abstract Window Toolkit (AWT) is Java's original platform-independent windowing, graphics, and user-interface widget toolkit.

Filter by
Sorted by
Tagged with
0 votes
0 answers
6 views

Clip content of a whole JComponent and it's children

I'm trying to clip the content of a tree of component (simply a JPanel with childs). In particular I'd like to clip around the edges, the panel is intended to be used as an overlay. And I've found ...
bric3's user avatar
  • 40.2k
-1 votes
0 answers
52 views

Getting too much output from one test case [closed]

I have a question using java software that goes: Continuing on from the previous task, add the following method to the AnimationViewer class: A public method named loadShapes(String[] lines) which ...
user's user avatar
  • 9
1 vote
1 answer
58 views

How to calculate mouse coordinates to world coordinates while changing resolution

I'm working on a Java game where I need to calculate mouse coordinates in world space while changing the resolution of the game window. I'm currently using the following code to perform the ...
GDjkhp's user avatar
  • 23
0 votes
0 answers
17 views

Why Bufferstrategy flushes / won't show() when outside of rendering loop?

The following code will flush/clear the current buffer of the canvas ( a black screen will be displayed for a split second maybe and after that nothing will be displayed - which is not what I expected ...
jacob12's user avatar
  • 173
0 votes
2 answers
30 views

Java AWT: MouseMotionListener cannot distinguish mouse buttons

So, in the code provided, I'm printing out the type of button that is pressed by using two interfaces, viz., MouseListener and MouseMotionListener. How do I make MouseMotionListener's mouseDragged ...
Sri Kavipriyan's user avatar
-2 votes
1 answer
39 views

Code was skipped after a instance of JPanel was created

I am making a copy of the game Tetris and have created a game panel. I was trying to swap the order of tetris.initGamePanel(); and tetris.initWindow(); in public static void main(String[] args){ ...
山宗陽成's user avatar
0 votes
1 answer
23 views

JVM/AWT displays Unicode characters differently on different platforms

I've been working on a little programming environment for Lisp-like languages. The environment can be run on JVM or on Android, and the JVM variant can be rendered to either Swing or terminal (using ...
Maciek Godek's user avatar
0 votes
1 answer
16 views

Java AWT Canvas - Multiple colors in one window

I was trying to make rectangles that have multiple colors with Java AWT, but whenever I use the setForeground(color) method, it changes the color of all objects in the window. Is there a way to change ...
new here's user avatar
0 votes
1 answer
38 views

Struggling to create an uneven grid in Swing

I have a working application that uses GridLayout to make a 2 by 2 grid, each containing a JPanel. The GridLayout worked just fine, I just did mainPanel.setLayout(new GridLayout(2, 2)), and everything ...
davidalayachew's user avatar
0 votes
0 answers
28 views

Why aren't all the Buttons being displayed correctly in a Container?

So I am learning Java with the IntelliJ software and am trying to learn how to add multiple ActionListeners to the program. I am using a video from the Programming Guru on Youtube to learn this. I ...
Martin Sieburg's user avatar
0 votes
0 answers
22 views

Java Get Path to Executable of Default Application

Is it possible to get the path to the executable of a default application? For example, suppose I set that files with the extension ".abc" should be opened with executable ABC.exe. I'd like ...
Bruno's user avatar
  • 1,329
1 vote
1 answer
56 views

Wrap text after a specified amount of characters in a JTextPane

Given a JTextPane, how can it be configured so that it wraps its text when: It reaches its component boundaries (functionality already provided by Swing) or when it reaches a certain character limit ...
tyrondis's user avatar
  • 3,364
1 vote
1 answer
46 views

Draw line with dash results a solid line in Java

I draw a line with [2/3f, 1/3f] dash in Java, but results a solid line. I also tried other dashs, here is the results: [2/3f, 1/3f]: a solid line [0.5f, 0.25f]: a good dash line [0.6f, 0.3f]: a dash ...
Dallon Xu's user avatar
0 votes
0 answers
64 views

InvocationTargetException From FontManagerFactory.java While Running XML To PDF Conversion XSLT1.0 FOP2.8 For svg:text

I am trying to render svg:text as water mark in my pdf below is the simple svg:text that I am trying to render: <xsl:template name="Draft"> <fo:block-container z-index="-1&...
Rito Sarkar's user avatar
1 vote
2 answers
94 views

How to close/hide/restore a Swing application according to the OS default behaviour

On Mac, apps are expected to "hide" into the dock when clicking the "x" button on the window's title bar, and restore when being clicked on again in the dock. On Windows and Linux, ...
tyrondis's user avatar
  • 3,364
0 votes
1 answer
33 views

Issue with Swing JTree Checkbox Behavior

Facing this issue with my code while working with checkboxes in a JTree. The root node is treated as a "Named Vector" in first iteration instead of a "CheckBoxNode"As a result, it ...
JamesB's user avatar
  • 525
0 votes
1 answer
36 views

Problem with Java GUI. Why does it show duplicated components at the beggining and when the size is changed by the user it shows how the GUI should be

I've been creating a JAVA GUI for create a project, that includes a timer and some other features, using swing and AWT. When I compile the project, it compiles, but the GUI doesn't seem right because ...
ConDuda's user avatar
0 votes
0 answers
33 views

JTree Node as Checkbox is unclickable

I'm currently facing a challenge with my JTree implementation, and I'm seeking to find a solution. The JTree displays a hierarchical structure with nodes and checkboxes, and I want to make the root ...
JamesB's user avatar
  • 525
0 votes
1 answer
40 views

How to delete pixels on a BufferedImage (or other components using Graphics)?

So I want to make a super basic lighting system for my games. And how I want to do that is draw the overall darkness on a BufferedImage, and then use ovals to remove pixels in the BufferedImage to ...
BlockManBlue's user avatar
0 votes
0 answers
15 views

Notification to show on the same screen as the application

I am using ch.swingfx.twinkle NotificationBuilder in my application. NotificationBuilder builder = new NotificationBuilder().withMessage(message).withTitle(title).withStyle(notificationStyle)....
Tanu's user avatar
  • 1,296
0 votes
2 answers
87 views

Creating and using an invisible, topmost, non-interactable window for "screen-drawing"

I've been struggling to get this to work. The only solution (but terrible solution) I found was re creating a new window every frame which is horrible for performance and other obvious reasons. Here ...
Novality's user avatar
0 votes
0 answers
27 views

Methods for improving efficiency when drawing paths in java.awt

I am using the java.awt.Canvas class for drawing in my application and it simply does not seem to be fast enough. After filling my screen with some hand drawn math I get to a point where I am running ...
JoPoLu's user avatar
  • 21
0 votes
0 answers
26 views

When inserting a node to root and calling fireTreeNodesInserted, what TreeModelEvent parameters to use?

I've read the [fireTreeNodesInserted](https://docs.oracle.com/javase/7/docs/api/javax/swing/tree/DefaultTreeModel.html#fireTreeNodesInserted(java.lang.Object,%20java.lang.Object%5B%5D,%20int%5B%5D,%...
null's user avatar
  • 889
0 votes
2 answers
42 views

place 3 or more components on top of each other and make them fit their parent

What I want to achieve is the following: place 3 or more components on top of each other. They are all the same size and are in the topleft position. Resize all components to match the size of the ...
Dante S.'s user avatar
  • 222
0 votes
1 answer
30 views

JFreeChart align Bar Chart left [duplicate]

I printed a bar chart using JFreeChart. But if I want to make the bars closer to each other using setCategoryMargin(-2) on my CategoryAxis, the Bar Chart appears to align in the center. Is there a way ...
matteo's user avatar
  • 3
0 votes
0 answers
56 views

Java AWT/Swing Frame.setsize() does not set intended size when below 3x3

As the title suggests, when trying to set setSize(int x, int y) and x, y are below 3, it defaults to 2. Trying setSize(1, 1) creates a 2x2 pixel frame, and setSize(0, 0) creates a 2x2 pixel frame. I ...
user22126574's user avatar
0 votes
1 answer
29 views

Problem drawing on JComponent via MouseMotionListener added to a JFrame

I want to draw ovals while dragging my mouse over a JComponent I added to a JFrame. I created two classes, one which extends JComponent, implements MouseMotionListener and overrides the paint(Graphics ...
pprts1's user avatar
  • 1
1 vote
0 answers
50 views

How to render an image without scaling on java Graphics?

i have screen with 4k resolution and 150% scaling on windows Main class ` public static void main(String[] args) throws IOException { JFrame frame = new JFrame(); frame....
Ярослав 's user avatar
0 votes
0 answers
30 views

Why is the click event of the custom layout for the Item of the JList component not functioning?

Within the confines of a JPanel, I have fashioned a JList component, its Item rendering implemented in a custom manner. Yet, I have unearthed a predicament wherein the ActionListener of the JList ...
YuJie Liu's user avatar
0 votes
0 answers
30 views

How do i implement the JPanel and JLabels of one class in another to the frame

Im currentl programming a pacman style game and i`m doing the gui right now. My Plan is to write seperate Gui classes and in this example i wrote the Gui for my Hearts. My plan is to combine all the ...
Resos82010's user avatar
0 votes
2 answers
38 views

IsEnabled not working when a function is triggered in Java applet

I want a button ("closeButton") to grey out when the function "openExplanations" run. But it is not working. Gives error Cannot invoke "javax.swing.JButton.setEnabled(boolean)&...
Vedant Bahel's user avatar
0 votes
1 answer
39 views

The import java.awt.Taskbar cannot be resolved and Taskbar cannot be resolved

`if(!Taskbar.isTaskbarSupported()) { JOptionPane.showMessageDialog(null, "Taskbar isn't supported!","ERROR", JOptionPane.ERROR_MESSAGE); System.exit(-1); ...
Anjali Yadav's user avatar
0 votes
0 answers
16 views

Why is my gradient not showing in the window with Java AWT

Background gradient not showing java awt I am trying to create a simple window with a gradient background. But i cannot figure out why is the gradient background not showing / drawing. import java.awt....
Gabrioche's user avatar
-2 votes
1 answer
51 views

How do I ensure my diagonal lines stay contained within a rectangle?

I'm trying to draw some lines to cross a rectangle diagonally but the issue is that the lines get out of the rectangle boundaries, look at this image to understand what I mean: here is the code used: ...
Mahmoud Ibrahim's user avatar
-1 votes
2 answers
34 views

Java Swing JLayeredPane not showing CardLayout cards & background image

I'm using Java 17 for a little project. I'm doing the Layout with the AWT CardLayout and the graphical components with Swing. I want to change my currently active JPanel in Window.java whenever I ...
fullstacknoob's user avatar
0 votes
0 answers
31 views

Redrawing the contents of a AWT JFrame every second

When i use Timer and TimerTask to have it run the code every second it doesn't draw to the JFrame but still runs the code. public void drawObject(Graphics g, int scale){ g.setColor(colors[rand]...
alex miranda's user avatar
1 vote
2 answers
53 views

Is there a way to catch when any JPopupMenu is shown?

I want to log every time any JPopupMenu is shown (visible). I tried to catch via AWT Events, but MouseEvent does not provide JPopupMenu due JPopupMenu might still be generating and not yet visible I ...
VextoR's user avatar
  • 5,097
-1 votes
2 answers
41 views

Why is the ActionListener not working with the buttons in Java GUI?

I'm working on a Java GUI application, and I'm having trouble getting the ActionListener to work properly with my buttons. When I click on the buttons, nothing happens, and the corresponding methods ...
RighteousRocks's user avatar
0 votes
1 answer
78 views

Font in Java AWT not rendered correctly when it's larger than 100 points

I'm trying to render the text into an image using JAVA AWT. When I use a font smaller than 100 points, everything works as expected. But when I use, for example, 240 points, then some parts of the ...
awarus's user avatar
  • 7
0 votes
0 answers
21 views

MouseListener is not triggered when I am clicking

MouseListener is not triggered when I am clicking. I first tried it without any labels and panel. It worked just fine as I could see the mouse coodinates and key pressed on my console. Here is the ...
Swasti's user avatar
  • 1
-2 votes
1 answer
70 views

How to add a background image? [duplicate]

In the code I tried to move "Hotelz.jpg" to the bottom of the layer, but it does not work How do I do that? I tried this code to add a background image, but it does not work I'm really new ...
Phx_DPyrexx's user avatar
-3 votes
1 answer
51 views

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "" while adding two numbers in calculator using awt [duplicate]

I don't know why this error is caused here. I have the java code below. I was trying to make a calculator and whenever I try to add two numbers it shows this error: Exception in thread "AWT-...
Tenny Xavier's user avatar
0 votes
0 answers
24 views

The gridlayout vgap changes on its own, how can I make it always the same?

I am making a messaging app where a server and a client communicate with each other by sending messages. I have a main panel where the messages are printed, and it is set with gridlayout and put on a ...
damby's user avatar
  • 3
1 vote
1 answer
39 views

Memory-efficient alternative to LookupOp for coloring a two-colors image?

Given a white and black image, no grey (in ARGB: 0xFFFFFFFF and 0xFF000000), I want to colorize the black in a specific color and the white in another specific color. I currently use the following ...
Olivier Grégoire's user avatar
0 votes
0 answers
70 views

My repaint() isn't doing anything and I'm at a complete loss

I've been working on this for some time now and I can't seem to figure out where I have gone wrong. I'm working on a VLCJ project and trying to use an overlay to display changes to the video, like ...
bobthebob55's user avatar
-1 votes
1 answer
46 views

Panel is empty after changing cards in CardLayout

I'm codding selection sort visualization. So, I got an issue: when I change panels(when I'm in main menu and I press button for visualization) I want my array to be painted on visualization panel, but ...
kirin's user avatar
  • 19
0 votes
0 answers
19 views

Java AWT Frame is unaffected by night light

I was building for the first time an actual application in Java using java.awt.Frame. But then I switched instead to javax.swing.JFrame, which I heard is more recent and generelly better (right?), and ...
nanto's user avatar
  • 1
0 votes
1 answer
62 views

How to make a JDialog work on a JFrame that is fullscreen

I'm writing a program using Swing and AWT and I have a JFrame that is fullscreen. On said frame I have a button that opens a JDialog on that frame. When I click the button it does create the jDialog ...
computer_goblin's user avatar
-3 votes
1 answer
59 views

Where can I find the implemented abstract Graphic class?

An abstract class is passed into paintComponent , and functions can be performed on it . Anyway , it sounds not real. So there must be a definition of concrete Graphics . I'm chewing on if I can refer ...
De Loris's user avatar
0 votes
0 answers
40 views

Graphics#drawString/FontMetrics calculation problems [duplicate]

I need help with the Graphics#drawString method: I want to correctly draw it and need correct calculations for text width/height and text position. These are my two test texts: <text id="first-...
SquidXTV's user avatar

1
2 3 4 5
132