All Questions
9,725 questions
0
votes
2
answers
67
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
70
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
26
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
0
answers
19
views
When using turtle-graphics in Java on Mac,the background color of the JButtons is not changing as expected
I want to create a program that randomly creates the number of horizontal and vertical grid layouts and fills them with the numbers that come out by rolling a dice. The screen size is 500×500, the ...
-1
votes
1
answer
48
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
94
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
62
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 ...
0
votes
0
answers
38
views
Problems reloading a JPanel image [duplicate]
I have a panel in my interface that will have an image inside it. Initially, it starts out empty. When I click on a button, it executes a logic that creates the image in the specific folder and then ...
1
vote
2
answers
40
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
63
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
56
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 ...
0
votes
0
answers
36
views
Weird whitish tint over video feed from the canvas frame
I have a JFrame, on that a JPanel, on that a JButton.
Of JButton, I have handled JButton.actionPerformed() event of it.
But when I click on the JButton to open the canvasFrame where the image be shown,...
1
vote
2
answers
133
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
53
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
51
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
57
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
65
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
2
answers
61
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
22
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
61
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
67
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
47
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
45
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
75
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
58
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
62
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
37
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
31
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
59
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
51
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 ...
0
votes
1
answer
38
views
Making my JLayeredPane background transparent in Java
I would like to stack 3 different 15 × 15 grids filled with JButtons on top of each other where one of them should be visible and the others transparent, but the JButtons should still function and ...
0
votes
1
answer
48
views
JDialogue's components won't show up before while loop ends
I am currently building a RPG game using built-in GUI and is trying to display a simple fight scene on a JDialogue. My partial code are as follows:
public void setupFight(Character c) {
...
0
votes
0
answers
51
views
Can I delete a certain character from a JList?
First of all, English isn't my native tongue. So sorry in adavance for any mistakes!
For a project of mine I want to have a list with numbers the user decides to put in, and all of these numbers get a ...
-1
votes
1
answer
49
views
Why does my update function complete without updating the db and it gives no error?
private void Approve_btnActionPerformed(java.awt.event.ActionEvent evt) {
int bonus = Integer.parseInt(bonus_txt.getText());
int sal = ...
0
votes
1
answer
134
views
How do I run my java code on my JFrame in eclipse?
I'm currently trying to create what I thought was going to be an easy Java program. I want to create a GUI that prompts the user to enter the day of the week and will spit out the chores they have to ...
0
votes
1
answer
62
views
Frame showing up super small Java Swing
could someone tell me why my frame is showing up super small/minimized? I thought I just had to pack my frame to resolve the issue but packing my frame does not seem to have any effect on the outcome.
...
0
votes
0
answers
31
views
JComponent added to JPanel doesn't appear?
I have searched a lot for this problem and did find similar problems but not exactly this so nothing has worked yet.
I am making a game like Vampire Survivors and right now I am trying to get the ...
0
votes
0
answers
34
views
Java paintComponent not display background image on JFrame
I am trying to display an image that have in a subdirectory of my project src, and from the testing that I have done, the path reference to utilize the image is correct, however, when I run the ...
0
votes
0
answers
51
views
How to add good quality image to JFrame?
After inserting a good quality image into the JLabel, the final image quality is less detailed (as if it had a lower resolution).original image JFrame screen after inserting. The difference may not be ...
0
votes
0
answers
39
views
repaint() leaves trace of object initial position
I'm implementing a JFrame program that is supposed to mimic balls bouncing with wall & between other balls in a concurrent setting. While the balls are correctly displayed and updated, it leaves ...
0
votes
0
answers
26
views
How to Implement SRCAND with Java?
If I want to use Java to implement the SRCAND effect of BitBlt() in VC++, that is, perform AND operation on the image and background. For the following example, how can I mix the red string AAAAAAAA ...
0
votes
0
answers
71
views
Coding battleship in java using Jbuttons in a Jframe
I'm trying to code battleship in a JFrame with 2 matrices of 2d arrays with JButtons. I have most of the code ready to go, but I'm running into a problem with placing the ships. The problem is that ...
0
votes
1
answer
74
views
How do I colorize the text in a JFrame Title bar
I have an application controlling hardware that has a JDialog displayed when the user wants 'backdoor' access to the hardware. That JDialog is filled with buttons and features and I don't want to ...
-1
votes
2
answers
46
views
Java : How to display a label inside a Jframe component
I try do display a text at the bottom of the container (JFrame) but it doesn't appear ....
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import ...
0
votes
1
answer
49
views
Problems with moving an object in Java Swing
I'm having trouble displaying the movement of a custom Jbutton object in Jpanel that has been added to the Jframe.
The chart is displayed but when the startMovement method is called the chart ...
0
votes
1
answer
72
views
Get accurate coordinates within JPanel in a JFrame
How does one get accurate xy coordinates from a JPanel placed within a JFrame.
I tried figuring this out on my own but the coordinates are slightly off and I dont know why.
I know this probably isn't ...
0
votes
0
answers
35
views
table is not visible in the window. How to fix it?
String[] columnNames = {"Customer ID", "Name", "Address", "Salary"};
dtm = new DefaultTableModel(columnNames, 0); // 0 is row count
customerDetailsTbl = new ...
1
vote
1
answer
108
views
Why does my ImageIcon disappear after using setLocation() on JFrame?
I want to move a JFrame window containing a GIF across my screen, but when I try the following:
icon = new ImageIcon(spritePath);
frame.add(new JLabel(icon));
frame.setSize(icon.getIconWidth(), icon....
1
vote
1
answer
53
views
Why is only one component appearing
I have a JFrame and for some reason only one component is appearing
public JFrame mainMenuFrame = new JFrame();
public JLabel welcomeText1 = new JLabel();
public JLabel welcomeText2 = new ...
-2
votes
1
answer
46
views
why isn't the square drawing when i type 1 or 2?
here's the code but I don't know why it doesn't work I've tried adding a revalidate and a repaint but the square won't draw, I'm trying to make the square move over a bit when 2 is entered and the 1 ...