9,966 questions
-2
votes
1
answer
75
views
Problems when trying to alternate frame transparency
A few days ago, I encountered a Swing error when trying to change the transparency of the JFrame (undecorated), which lost its color and transparency information (instead of displaying the selected ...
0
votes
2
answers
99
views
How to set an image filename
I made a Java program with Swing libraries that displays text and an image. Both the text string and the image filename are set via a set method, but while the text is displayed correctly, the image ...
0
votes
0
answers
24
views
Remove Jpanel from jframe
I'm working on a basic Hidden object game for fun. Im not a professional coder by any means. At the main menu of the game (where you select start game, exit, resume, or how to play) I have 4 Jbuttons ...
1
vote
1
answer
69
views
How should I set up a JPanel to display with white space?
I'm trying to create a class which represents a playing card as a JPanel, (which I add to a window in another class), but I don't know how to make the panel stay at a specific size when I add it to ...
2
votes
1
answer
81
views
How to reduce the height of a JPanel used as a header in Java Swing?
I’m building a simple Java Swing UI and want a thin red header bar at the top with just a title label (“Unit Converter”).
However, the JPanel takes up too much vertical space. I only want a slim ...
0
votes
1
answer
176
views
Change titlebar of java swing by FlatLaf causes entire UI change
I was building a calculator project and I am new to JAVA & stackOverflow. So far build the entire thing except the titlebar which is default. As titlebar is controlled by OS we can't make direct ...
0
votes
1
answer
85
views
adding items to a JPanel with a button
I've been trying to create a program that tracks a shopping list and adds new JLabels whenever the corresponding buttons are pressed, but for some reason whenever I press the button nothing new comes ...
0
votes
0
answers
82
views
My code has suddenly started cropping out sections of my JFrame with no changes or alterations to the code
I've been coding a project in Netbeans on Java, and it makes use of a series of JFrames for login screens, main menus etc. I was coding it yesterday and was working just as expected, with everything ...
0
votes
0
answers
60
views
Why are my buttons not showing, only the label is visible? [duplicate]
I’m trying to display two buttons (“Increase” and “Decrease”) in one panel and a label (“Points:”) in another that should be located under Panel1. But when I run the program, only Panel2 with the ...
-1
votes
1
answer
76
views
Is it common practice in Java to add JPanels with custom layouts to a JFrame to organize components? [closed]
I'm learning Java Swing and wanted to make sure I understand the common approach to building GUIs.
As far as I understand, the typical workflow is:
Create a JFrame as the main window.
Add one or more ...
0
votes
2
answers
90
views
Why does my JButton lose its full width when added via a JPanel in BorderLayout?
I’m an absolute beginner with Java Swing and trying to build a simple GUI for a unit converter.
In the following code, I add a JButton directly to the JFrame using BorderLayout.PAGE_END. The button ...
-1
votes
3
answers
134
views
Swing: How to center a button near the bottom of a JFrame without using setBounds()?
I’m working on a Java Swing application and would like to place a button so that it is horizontally centered and vertically positioned near the bottom of the window — similar to how a typical “Submit” ...
0
votes
1
answer
36
views
ActionListener cannot recognise my buttons?
I'm writing code for a fairly simple GUI, but I'm having some trouble getting my buttons to be functional.
Working on Eclipse IDE.
I have my frame, and all items I wish to add to it (i.e. buttons, ...
0
votes
1
answer
109
views
How to Display Items In JPanel to use for Inventory System?
I'm currently making an inventory display menu to manage tools around the shop easier.
MainMenu (JFrame Form)
I want to make a GUI that populates a JPanel in a JScrollPane with a premade JPanel Form ...
1
vote
1
answer
79
views
Creating a "second frame" for Full Screen in a Java app
I've had a few suggestions on SO regarding Full Screen for a Java app, and the most-offered suggestion is to simply create a second JFrame into which the app's main content can be moved.
In theory, ...
0
votes
1
answer
47
views
The content will not appear how I want it to with setBounds
The panel is showing up blank and even when I setContentPane(null), the words on the panel wont show up how I want them to with set Bounds.
I tried changing the order of my configurations for the ...
1
vote
1
answer
102
views
I have created a separated class for the JFrame, but now the JLabel is not showing up
I am trying to make a frame with a label, (I have created a separate class for the frame), but idk why the label isn´t showing in the frame...
import java.awt.Color;
import javax.swing.ImageIcon;
...
0
votes
1
answer
35
views
Why I can't access a method from my custom JPanel?
I have a JFrame with a JPanel inside.
MyFrame class:
public class MyFrame extends JFrame {
private JPanel contentPane;
public static void main(String[] args) {
new MyFrame()....
0
votes
1
answer
70
views
Add ImageIcon + text to JLabel
I would like to add an image and some text to the cell of a JTable.
Here is the GUI class that seems to cause problems:
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax....
0
votes
0
answers
150
views
Blocking method on a JFrame (or JDialog)
I need that my readString method be blocking until user input his text into the TextArea. This is a model of my problem:
public class Consola
{
private final JDialog dialog;
private final ...
0
votes
0
answers
71
views
How can I fix transparent lines in my scaled images (Javax.swing)?
I am trying to make a small games with a native resolution of 320x180, then scale it up for a bigger window. but I'm getting transparent lines in my sprites.
right now I'm drawing to a BufferedImage ...
0
votes
2
answers
75
views
How can I make a while loop wait for a JButton to be pressed?
I am very new to Java, and am trying to make a program that asks to use to guess a random number between 1 and 77. How can I make the while loop in this code run only when an answer has been provided ...
1
vote
2
answers
116
views
JDialog is interfering with JFrame owner MenuItem accelerators
I have a JDialog (non modal) with a JFrame owner. The problem I have is the that when the JDialog has the focus it is preventing the ActionListener associated with the JFrame JMenuItem accelerators ...
0
votes
1
answer
65
views
How to Enable Keyboard Navigation in a Non-Focusable JPopupMenu in Java Swing?
I am working with a JPopupMenu in Java Swing and need to allow users to navigate through the menu using the up/down arrow keys. However, I am setting the JPopupMenu to be non-focusable (popupMenu....
0
votes
1
answer
68
views
Set data from WebSocket Server to JFrame components
I have WebSocket server:
@ServerEndpoint(value = "/demoApp")
public class MyWebSocketServer {
@OnMessage
public String onMessage (String message, Session session) throws IOException {...
-3
votes
2
answers
111
views
Why are my Java text boxes only holding the last number of an imputed array? (I am using a JFrame Form for the GUI)
I have tried to get a textbox to display an array, but as far as I have tried it only shows the last number of the array
ex: array gives: 1, 24, 18, 98, 100, 78, 63, 24, 77, 46
Textbox displays: 46
...
1
vote
2
answers
79
views
How to assign a class variable using the value obtained from JTextField in Java
import javax.swing.*;
import java.awt.event.*;
public class Test {
private String textFieldValue;
public Test() {
JFrame frame = new JFrame ();
JPanel panel = new ...
1
vote
2
answers
62
views
zooming and mouse click with JFrame and AffineTransform
I'm having a issue with mouse click being tied to JFrame location while a BufferedImage is being displayed and setting the location of the mouse click relative to the scaling of a zoom.
(code is from ...
0
votes
2
answers
97
views
Resizing JFrame issues with a JPanel and JTable using GridBagLayout
I'm in the process of testing combining a JPanel (controls) and JTable (the data) in the same frame and have run into issues when trying to resize the JFrame that contains them.
The first issue I am ...
-2
votes
1
answer
75
views
why did my color of JPanel fill up all the window gui? I didn't know if there's something wrong in the code or the compiler?
the window appeared like this:
this is my code:
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class gui2 {
public static ...
1
vote
2
answers
686
views
What does "Canonical constructor cannot delegate to another constructor" mean?
Im new to programming and following this tutorial for a weather gui app in java. Below is the very small amount of code I'm working with so far. Where I am getting errors is at the "super(...
1
vote
0
answers
67
views
Adding ZOrder to JLabels causes them to Flicker in Jframe
I am trying to make a 2D game using Java Swing, but I am running into some trouble. I added ZOrder to my JLabels because I wanted them to appear in a certain order, but it caused them to start ...
0
votes
1
answer
63
views
Unable to deselect a JButton once it has been clicked
So I am writing a program which has several layers of menus using a JFrame with JButtons but once the user clicks a button that button ends up stuck as selected and I cannot update it. Any help please?...
0
votes
1
answer
109
views
Illegal Argument when trying to draw
I'm trying to draw a chess piece on the board I created but keep getting an error that seems my picture can't be found.
Exception in thread "main" java.lang.IllegalArgumentException: input ==...
2
votes
1
answer
78
views
How do I make this grid display in another jframe?
I have coded a MazeClass that paints a grid and has a method to change the color of a block on the grid. I would like to display this grid in a separate class on a jframe in the position I want to. ...
0
votes
1
answer
40
views
how do i make my g.drawline draw ontop of my JTextFields in a JFrame
i am attempting to make a soduku solving java program. i want it to be graphical and graphical isnt an area ive really explored before.first ive created a graphics method to draw all my needed lines. ...
0
votes
1
answer
55
views
My components in two different panels are too small and don't fit to the frames size, how can I fix this?
I made a JFrame (size: 500 , 600) that uses GridBagLayout to place two JPanels (one using GridLayout and the other using GridBagLayout) on top of each other; however, when I run my JFrame the ...
0
votes
2
answers
640
views
How do I Get JFrame to Display JPanel Text Content Even When Called by Action Event?
I have a simple JFrame dialog, that should display "Please Wait" message while the main program completes other activities (which may take anywhere from 30 seconds to more than 10 minutes):
...
0
votes
0
answers
28
views
Simple animation using a JLabel and ImageIcon throwing an exception
I'm making a simple static animation at the start of my program, and it uses a timer and ImageIcons to work. Here is the code:
int staticChecker = 0;
private void btnStartMouseClicked(java.awt....
0
votes
1
answer
73
views
Is it possible to connect two different JFrames to one single class?
I make two forms but I have this problem where my second form that will appear after we press a button on the first form could not get the data from the subclass. The plan was I want to only use one ...
0
votes
1
answer
98
views
How does JButton call the actionPerformed method?
I was trying to understand exactly how a JButton object works.
I created the below SampleFrame object that extends JFrame.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
...
1
vote
0
answers
60
views
Starting X and sometimes Y coordinate of JFrame is displaced
Just recently started playing around more with Swing and right now I am trying to build an Algorythm Visualiser. The array being displayed is displaced. The starting X coordinate is shifted to the ...
0
votes
0
answers
59
views
my program still does not recognize txtFechaDev, even though I have the jcalendar 1.4 library
is my first time here, i have a problem in this program, I download the jcalendar 1.4 but the problem is in textFechaDev, it seems that the program txtFechaDev is not declared or there is an error in ...
1
vote
1
answer
93
views
Graphics2d on JPanel
I want to make a program in Java that drops a square at the position of your mouse. For that I wanted to draw a grid as background and then add the squares but as soon as I add a new component to the ...
0
votes
0
answers
63
views
Issue with object arrays and their usage among frames
I need to find a way to handle the object array to send it to the other frame "Start" I've tried various ways but I can't, I'm just a beginner in the field of OOP, I've tried creating ...
1
vote
1
answer
80
views
Image URL syntax
I am trying to make a background image in a java jframe window, but when I try to initialize it, I get a null pointer exception saying the location url I put in is null.
I've tried the following:
...
0
votes
0
answers
42
views
Add image as icon for window
this is the code
import javax.swing.*;
public class test {
public static void main(String[] args) {
System.out.print("Starting up...");
createWindow();
}
private ...
-1
votes
1
answer
40
views
Java KeyPress is getting the value before the key press, not the value during the key press
I'm writing a Java program that generates 5 random letters when user press G. After pressing G, if user press S, the next pressed key would be compared to the random generated letters to check if it ...
0
votes
2
answers
81
views
getResource not retrieving images in Source Package
I am trying out a java with Ant slideshow in a video I found. I have made the output, and the window is appearing, but none of the images are being shown.
I suspect I have done something wrong ...
0
votes
1
answer
77
views
Continue Detecting Input with KeyListener While Typing In a JTextField
I'm currently working on a small utility window for another application and I'm running into the issue that KeyListener input stops detecting input while a user is focused on a JTextField.
I've made a ...