Questions tagged [swing]
Swing is a user-interface toolkit in Java and is shipped with the standard Java SDK. It is contained within the package javax.swing.
80,453
questions
-2
votes
0
answers
21
views
Open browser and search with Java [closed]
I want a button (which is already coded and working) which, once pressed, will open a browser and search a link which I will provide myself in the code.
But when I re-use code which I found on the ...
0
votes
2
answers
21
views
How can I change the whole look of a JTextField
I want to change the look of the whole JTextField but still want it to be editable. The first picture shows a normal JTextField, the second picture shows, what I want it too look like. So basically it ...
-1
votes
0
answers
10
views
How to close jframe from button in jinternalframe in Java Swing [duplicate]
I have jinternalframe in jframe and i wanna close the jframe by press button in jinternalframe. if i use "this.dispose()", it only close the jinternalframe, not the jframe.
0
votes
0
answers
42
views
How to make a zoom feature in a JLabel (java)?
My code until now looks like this:
lblMap2 = new JLabel();
lblMap2.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent arg0) {
int mapX = lblMap2....
0
votes
1
answer
38
views
How to close JFrame without closing another
I know this question has been addressed many times, but I tried everything to make it work properly. First and foremost, I create a JDialog as my loading pop-up when the user login is legitimate. Then ...
0
votes
0
answers
27
views
How to switch JPanel with buttons on each individual panel?
I'm new to Swing and I'm trying to figure something out. I'm having difficulty explaining what I'm trying to do and I can't find anything online so I wrote a program demonstrating what I want to have ...
-3
votes
0
answers
16
views
Frame gets hanged while updating data in CRUD operations using JAVA swing [closed]
I am trying to to do CRUD operations using Java swing. I could insert the data in the Oracle table, but while updating the data the update button and Frame gets hanged.
protected void ...
0
votes
0
answers
21
views
java returns error:'model.Movie: method <init>()V not found' in xml parser event though i have a constructor [duplicate]
java returns error:model.Movie: method <init>()V not found in xml parser event though I have a constructor in my class it cannot inittialize an object. I have tried rebuilding the project, ...
1
vote
2
answers
31
views
Creating an undoable JTextField
I've implemented an undoable JTextField, the issue is when I create more than one, it is only undoing the last instance that is created. The code is below - to replicate, enter some text into the ...
-1
votes
1
answer
35
views
How to individually set the width of a row on a table/scrollpane
i have a DefaultTableModel:
DefaultTableModel model = new DefaultTableModel(data, beschriftung)
{
// Returning the Class of each column will allow different
// ...
-3
votes
0
answers
38
views
How can I draw a rectangle for each thread in Java? [duplicate]
I'm trying to build a program that, when I press a button, it starts 2 threads and for each thread it draws a rectangle in the panel. However instead of displaying two rectangles as a final result, it ...
0
votes
0
answers
30
views
MigLayout hidemode is not working and cannot hide component
I have been using MigLayout for a while and i never encountered this problem. For some reason the hidemode contraint is not working and i can't make it hide a button.
Here is a code snippet that ...
0
votes
1
answer
32
views
How can I create a JTextArea with Autocomplete?
I want to make a program in which when I write in the JTextArea, but when I write a word, it gives me a suggestion on how to complete it. I tried Swingx's AutoCompleteDecorator, but when I finished a ...
-2
votes
0
answers
21
views
How can i close all child jframes when i hit the logout button from parent jframe [duplicate]
I have a test system and i want the log out button from the admin dashboard to close all the child frames created.I am failing since if i use the parent.dispose() method it disposes the parent but ...
0
votes
1
answer
38
views
managing a swing Interface with JButtons performing actions
I am doing a Battleship game with Java Swing GUI. There are several things i still need to implement, but right now i am trying to let the user select a cell in interface and make this action actually ...
0
votes
0
answers
48
views
Screenshot with transparent background
I created a program with several JLabels. Each of them shows a png file with transparent background. With this code I can overlay them and take a screenshot, but the panel is also taken.
How can I do ...
0
votes
0
answers
26
views
Java Swing Icon wont show up [duplicate]
My icon wont show up, I had this problem before even with images on labels.
import javax.swing.*;
public class Main {
public static void main(String[] args){
JFrame frame1 = new JFrame()...
-4
votes
0
answers
19
views
Checkbox dynamic java mysql [closed]
hy everyone
I start in java language, I work on a desktop project in java swing with mysql database.
my question is how can i display dynamic checkbox from the database for multiple choice from the ...
-2
votes
1
answer
57
views
How to utilize sleep method for calculator error
I am trying to set the calculator text to an error message, wait for 2 seconds, then clear the field text. Below is my current code.
public static void wait(int ms) {
try {
Thread.sleep(ms)...
-1
votes
1
answer
32
views
How to have multiple images and text on a content page?
I'm writing a program for a "Ski Area" (I hope that's the English term).
If you know a little bit about skiing, you know there are tracks with different difficulties. Now I want to show all ...
-1
votes
1
answer
25
views
How to align a JTextField that it is always on the far right side of the window?
I have a normal content pane in Java (IDE: Eclipse) and a JTextField.
Now I want the text field to always be on the far right, even if the size of the window changes. Is this somehow possible?
-1
votes
1
answer
30
views
Exception in thread ... JComboBox, Jbutton and actionlistener [duplicate]
I am working on a school project and I want to add text from a text field through a button to a combo box. I save the Object with its attributes and then I add it to the combo box: in my case ...
-1
votes
0
answers
27
views
Why are the elements of panel not showing when bg is applied in Java Swing?
So I had been working on a project lately and I was facing a problem while adding the background image. So when I use the following code:
JLabel bg=new JLabel();
bg.setIcon(new ImageIcon("C:\\...
0
votes
1
answer
26
views
Java GUI- Set the Login Page to appear before the main Frame
I'm working on this code currently which implements a login page right before the main one. The code is as follows:
public class TestFrame extends JFrame implements ActionListener{
private JFrame ...
-1
votes
1
answer
58
views
How to add KeyListener to a Jdialog in Java Swing
I have the code below, my goal is to add a KeyListener to the input dialog in such a way that if the user presses the CTRL+N, the cursor should move to the next word in the textfield. But when I run ...
1
vote
1
answer
43
views
How to decrement the quantity in a specific row while clicking
I have a problem in my code while clicking the selected row the quantity reset to 1
I want to decrement it by 1 and also when the quantity hits the minimum value the selected row will be removed.
BTW ...
-2
votes
0
answers
23
views
How can I import a java swing form attach from IntelliJ to eclipse [closed]
i want to change from IntelliJ to eclipse but form file cant work in eclipse, need some helps
1
vote
1
answer
38
views
JFrame isn't painting after creating it with a button
I want to have titlescreen and open a game by clicking a button. When i call the play()-method of my project normally, it draws the first level. But when i call it with a button, a white screen ...
0
votes
1
answer
53
views
Run cmd commands in the background through java
I am creating a GUI in java that requires a set of commands to be run through the command line one after the other in the background after the user selects a file and clicks a button in the GUI. The ...
0
votes
0
answers
18
views
Java GUI Swing Calendar [duplicate]
I wrote a code to make a calendar using Java swing. The error does not appear, but the code does not execute.
I would appreciate it if you could point out the wrong code part.
package Discharge_Day;
...
-1
votes
1
answer
53
views
How can I align text in a BufferedImage as columns? [closed]
I am using BufferedImage and Graphics2D to generate a GIF image, but I am struggling to have the layout like in the picture below. I am not even sure if it's possible at all.
The GIF will be animated ...
-1
votes
2
answers
45
views
Managing panels (GridLayout) size in a BorderLayout JFrame
So, i'm making a java battleship game with a GUI from Java Swing. I actually designed the borders (a very initial way) and now i'm trying to make a well-sized board. Consider that the board are the ...
-1
votes
0
answers
30
views
Calling a method of a class into another class of the same package (Java) [duplicate]
So I have 2 classes from the same package(gui)
What I'm trying to do is use the user input from the class "teacherLogPanel.java" ,after the user has logged in, into the class "...
0
votes
0
answers
47
views
There is always a delay or bug when running JPanel & JFrame instances (Mac M1 Pro)
I'm a beginner to coding. I'm using IntelliJ on a MacBook M1 Pro. So far most things went great and the compiling time is fast. Apps where everything runs in the Terminal work perfectly.
Unfortunately,...
-2
votes
0
answers
18
views
adding a static textfield [duplicate]
I designed a gui with a text field. I'm trying to access it (and "put a new String in it") from a different method but it doesnt work since the method is static and the text field is not. I ...
-2
votes
0
answers
34
views
Java: Scrolling through listed JPanels [closed]
Im working on a Code that needs to list various Account datas. I already did create the code to generate the needed JPanels, but I dont know how to implement them on a JScrollPane.
I want a Design ...
-2
votes
2
answers
56
views
Filter out files older than a week JFileChooser - Java [closed]
I'm quite new to programming, in fact I just finished school and just started in an IT Department until I start University in some months.
However, I was given the task to make a program that copies ...
0
votes
0
answers
22
views
How to (dynamically) set the name of a JButton with Action constructor [duplicate]
alright so i'm trying to program a simple GUI-based calculator in Java, only covering integer arithmetics.
So far i only got the layout, now i'm trying to add functionality. The idea is to append ...
0
votes
0
answers
21
views
Is there a drawImage() function that draws a circular subset of an image onto the screen? [duplicate]
Currently, the closest drawImage() has the following signature:
public abstract boolean drawImage(java.awt.Image img, int dx1,int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt....
-2
votes
0
answers
36
views
JButton can't click [duplicate]
import java.util.Vector;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
...
-1
votes
0
answers
23
views
Selecting one value from jComboBox but display two value in the Jtable [closed]
I have a jcombobox that has a value from my database and what I want to do is, whenever I click the name from the jcombobox and I want the specific value to display in the jtable which is the ...
0
votes
1
answer
29
views
Opaque background which doesn't affect foreground AlphaComposite [closed]
I have a black background and want to draw a number of BufferedImages containing filled circles. Outside the circle in the corners of the rectangular BI I set the alpha component to be transparent so ...
-1
votes
0
answers
22
views
JTree baground color change
import java.awt.Color;import java.awt.Component;
import javax.swing.JTree;import javax.swing.SwingUtilities;
import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree....
-1
votes
1
answer
37
views
Why label.getY()-10 could move up the component instead of move down? [closed]
here are the codes, just wondering why the componments could move up with "getY()-10", with learning some Math concepts, I assume it should be "getY() +10".
https://en.wikipedia....
1
vote
1
answer
48
views
Add JFXPanel to JDialog
I am trying to create a modal dialog that asks user for input. My program uses Swing for building gui but since i want to style my components with css i am using JFXPanels instead of regular JPanels. ...
-3
votes
0
answers
25
views
Need some creating a blinking panel [closed]
So I am working on a simple program for class, and I want to create a blinking panel after the user interacts with a series of dialog boxes. So far the first two parts of the program seem to be ...
-1
votes
1
answer
43
views
How do I use a separate method to call the paint component method and draw a rectangle?
I am using Swing to create a GUI which would draw a new rectangle every time a method runs.
I want to use variables that would get incremented and continue making new rectangles in a series.
My goal ...
0
votes
1
answer
66
views
How to move an image on a Graphics2D after a user clicks it
I implemented MouseListener and on mousePressed, I get the x-axis and y-axis the piece is positioned on when the mouse is pressed, and on mouseReleased, I get the x-axis and y-axis the piece is ...
-1
votes
2
answers
61
views
Where to put action listeners?
I'm a little confused about where the best class is for ActionListener instances in a small Swing application.
If I have a Controller, a MainFrame for the main JFrame and various JPanel containers ...
-1
votes
0
answers
20
views
Is it safe to transform (setMaximumSize, setMinimumSize, setPreferredSize) calls into a setSize call?
I am working with some legacy code and would like to know if it is safe to refactor the following sequence of instructions:
final var button = new JButton();
button.setMaximumSize(new Dimension(x, y));...