Java project using Swing

Hi, if anyone knows about Swing in java, there's a project i'm doing a To Do List Task, so i'm doing it between JFrame, one for adding the list, and other that displays when the user adds the new task, but I dont know how to storage the windows and show them into a Dashboard (Im currently saving them in a class which contains the List of Lists that the user adds), also, whenever the user wants to go back to the principal menu, it doesn't let me execute it, so if someone knows a better way to travel between JFrame without lossing the storage in each one, or if it is better to use just one JFrame and use CardLayouts, tysm
111 Replies
JavaBot
JavaBot2d ago
This post has been reserved for your question.
Hey @CADAN! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
bassus
bassus2d ago
1. Never use 2 JFrames for something like that. Use one base JFrame and work 2 JDialogs 2. What you are describing sounds like you would want to use a JList field to store data in^^
JavaBot
JavaBot2d ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
CADAN
CADANOP20h ago
yup, I figurated out that it wasn't necessary so I put just one JFrame to run the JPanel menu and the JPanel for the list that the user creates, I didn't knew that JDialog existed, can you tell me why should I use JDialog instead of JPanel? 2. yep thats what im triying to do, but i dont really know much about Swing and how to integrate it to my code 😿
bassus
bassus20h ago
Okay, wait. Asking whether a JDialog or a JPanel is the right choice is like asking if you should use a spoon or a chainsaw. Good luck eating soup with a chainsaw and cutting a tree with a spoon. What do you actually want to do? Show a to do list and add task or also be able to delete those tasks? Most importantly you will need a JList.
CADAN
CADANOP20h ago
yes exactly
CADAN
CADANOP20h ago
there is it
No description
bassus
bassus20h ago
Yeah For that you will need JPanels, JList and JDialog. I have to read up though, how exactly you used them, gimme a second^^
CADAN
CADANOP20h ago
ok, take your time ty
bassus
bassus20h ago
Like it depends a bit. Are those to do items just strings? Like, is that enough?
CADAN
CADANOP20h ago
Actually It came pre-established like that, I havent touched it im trying rn to integrate the JPanels to the JForm
CADAN
CADANOP20h ago
but it doesn't let me modify the part of the code that is underlined in yellow
No description
CADAN
CADANOP20h ago
bc im doing it with the Java graphical editor
No description
bassus
bassus20h ago
what? with netbeans?
CADAN
CADANOP20h ago
yes with neatbeans
bassus
bassus20h ago
Sry, but i won't help you building atrocities against best practice. The code in the screenshot is already violating style guidelines, sry.
CADAN
CADANOP20h ago
😶 why is an atrocity?
Madjosz
Madjosz20h ago
Oh, Netbeans is still including the full-qualified class name in the generated code?
bassus
bassus20h ago
Already the first line:
public class FRMGestor extends javax.swing.JFrame
public class FRMGestor extends javax.swing.JFrame
You should write:
import javax.swing.JFrame; //Or javax.swing.*;

public class FRMGestor extends JFrame
import javax.swing.JFrame; //Or javax.swing.*;

public class FRMGestor extends JFrame
CADAN
CADANOP20h ago
dude im new into coding, I just want to guide my project well thats why I entered in this discord server to seek help
bassus
bassus20h ago
Yeah bro, that was no attack on you. Sry if i offended you^^
CADAN
CADANOP20h ago
:clueless: bro it just The code was just generated like this, am I not telling you that I am doing it from the Java graphical editor
Madjosz
Madjosz20h ago
This is just generated code by Netbeans. You won't clean it up.
bassus
bassus20h ago
I'm just saying, pls don't use NetBeans Graphical Editor for Swing. Use Eclipse, IntelliJ, VSC, whatever and i gladly will help you 😄
CADAN
CADANOP20h ago
YES AND IT SUCKS I DONT LIKE IT, but I thought I could save time by organizing it graphically instead of fighting with the code to make look pretty the interface
bassus
bassus20h ago
Bro, i want to really do bad things to the developers of NetBeans. Biggest crime against good code ever committed ._.
Madjosz
Madjosz20h ago
Every generated code is the biggest crime against best practice code.
bassus
bassus20h ago
Again, if you want to, join me in voice and i will teach you how to write that shit clean from scratch, but without the editor pls.
CADAN
CADANOP20h ago
I can try with IntellJ, but idk how to use it
bassus
bassus20h ago
Deal
ayylmao123xdd
ayylmao123xdd20h ago
lombok is amazing 😤
CADAN
CADANOP20h ago
😿 ok I understood, but I blame my teacher for teaching me like that
bassus
bassus20h ago
Yeah, your teacher is not a good coder. Not your fault
Madjosz
Madjosz20h ago
I am not saying you shouldn't use it. Just don't expect the generated code to look good.
ayylmao123xdd
ayylmao123xdd20h ago
maybe thats just how he has to teach depends
Madjosz
Madjosz20h ago
Nah, you need a compiler plugin for it.
CADAN
CADANOP20h ago
Oh believe me I have a lot to say about my teacher lol, Im seeing Lists and he gives us code already generated, so we dont learn to much
ayylmao123xdd
ayylmao123xdd20h ago
a single getter looks better than 20 get methods
bassus
bassus20h ago
Lol, what a noob^^
ayylmao123xdd
ayylmao123xdd20h ago
is this university or high school
CADAN
CADANOP19h ago
unfortunately university
ayylmao123xdd
ayylmao123xdd19h ago
interesting looks like he just doesnt care
CADAN
CADANOP19h ago
I don't think is good enough as a teacher 😿 , i really want to learn programming but like this, I think I'm committing crimes against humanity lol
ayylmao123xdd
ayylmao123xdd19h ago
well boring stuff aside do you want the data to save between switching pages or between application startup
CADAN
CADANOP19h ago
for now between switching pages Later between the applicaction startup
CADAN
CADANOP19h ago
ok now what
No description
bassus
bassus19h ago
Bro, what should the volver button even do?
CADAN
CADANOP19h ago
go to the principal menu and theres where the problem started
bassus
bassus19h ago
Uhm there is a principal menu?
CADAN
CADANOP19h ago
well yeah for the dashboard of the list?
ayylmao123xdd
ayylmao123xdd19h ago
so like when u go to the menu
bassus
bassus19h ago
What do you mean by dashboard of the list? What does it look like?
ayylmao123xdd
ayylmao123xdd19h ago
and u go back to the list
CADAN
CADANOP19h ago
is like this
No description
ayylmao123xdd
ayylmao123xdd19h ago
the stuff in the list disappears
CADAN
CADANOP19h ago
thats like the dashboard
CADAN
CADANOP19h ago
and this was going to be like the other window
No description
CADAN
CADANOP19h ago
for the user to put his tasks
bassus
bassus19h ago
This will be the JFrame this will be a JDialog
CADAN
CADANOP19h ago
thats what im trying to figure out, how to save the information in a class, how to show them in a graphic context
ayylmao123xdd
ayylmao123xdd19h ago
ummmm like you got a bunch of objects
bassus
bassus19h ago
You normally would do this in a 3-layered architecture
ayylmao123xdd
ayylmao123xdd19h ago
and for each object show them in a list
CADAN
CADANOP19h ago
yes sm like that
ayylmao123xdd
ayylmao123xdd19h ago
oh ok
CADAN
CADANOP19h ago
ok
ayylmao123xdd
ayylmao123xdd19h ago
do you have adding to list already implemented like to the object
CADAN
CADANOP19h ago
and how it would be, like we were talking, one JFrame and two JPanel or what yes
ayylmao123xdd
ayylmao123xdd19h ago
so whats the problem cuz like idk what it is lmao
CADAN
CADANOP19h ago
this is where it Storages,
No description
No description
No description
ayylmao123xdd
ayylmao123xdd19h ago
yes
CADAN
CADANOP19h ago
yes but idk how to show like those clases in a graphic way
ayylmao123xdd
ayylmao123xdd19h ago
oh
CADAN
CADANOP19h ago
thats why im seeking help with java swing IDK how it works 💀
ayylmao123xdd
ayylmao123xdd19h ago
so whats in storage show on gui yes or no @bassus you know swing or no
bassus
bassus19h ago
I do But i'm currently still reading up on it, it's been a year since i last used it^^
ayylmao123xdd
ayylmao123xdd19h ago
great this item1 item2 you added manually right not through code
bassus
bassus19h ago
I know how to make it work, i don't know, how to make it pretty 😄
CADAN
CADANOP19h ago
It generated like that
ayylmao123xdd
ayylmao123xdd19h ago
ok
ayylmao123xdd
ayylmao123xdd19h ago
Stack Overflow
How to display a list of objects as a JList in java swing?
We are asked to build a system in Java Swing no drag and drop and I cannot understand how to display a list of objects in a JList. I have a GUI class that creates a JFrame, JPanel, and an empty JLi...
ayylmao123xdd
ayylmao123xdd19h ago
How to Use Lists (The Java™ Tutorials >
Creat...
This Swing Java Tutorial describes developing graphical user interfaces (GUIs) for applications and applets using Swing components
ayylmao123xdd
ayylmao123xdd19h ago
check these out
CADAN
CADANOP19h ago
ok i think im not learning anything, i think im confusing everyone here, so im going to do the code again, and not use the generator of the grafic interface 💀 ok thx
ayylmao123xdd
ayylmao123xdd19h ago
idk swing so i can only send links lol
CADAN
CADANOP19h ago
ty
bassus
bassus19h ago
okay Cadan
bassus
bassus19h ago
A very basic way to organize your fun
bassus
bassus18h ago
@CADAN How to make it pretty? No clue. But it works And sure, you could write nice little sub-methods for onDelete and onAdd, but i was lazy xD Actually no, i know how to make it pretty, with some bs chatgpt hacks xD Ah btw, you should maybe do this.add(new JScrollPane(myList), BorderLayout.EAST); without a ScrollPane that shit is a bit goofy
CADAN
CADANOP18h ago
right thanks im also changing to INTELLJ
CADAN
CADANOP18h ago
better? aslkdj
No description
bassus
bassus17h ago
Why is there a JFrame field? private JFrame frame;?
bassus
bassus17h ago
Sry, don't want to be mean But have you understood how to use JFrames and such in swing? But, yeah overall you are going in the right direction
CADAN
CADANOP17h ago
you're right, I'm overwriting it. so, so
bassus
bassus17h ago
No, you alread have a JFrame here. It's called this
CADAN
CADANOP17h ago
yea sorry
bassus
bassus17h ago
Stop apologizing, all good^^
CADAN
CADANOP17h ago
No description
CADAN
CADANOP17h ago
🫡
CADAN
CADANOP17h ago
one more question, anyone knows why in IntellJ the Run sometimes works and when I excecute it again it appears like this
No description
No description
bassus
bassus17h ago
Uhm What
ayylmao123xdd
ayylmao123xdd16h ago
maybe you are running a different file
CADAN
CADANOP16h ago
idk is just that when I run the program sometimes it appears right, then I again excecute it and appears empty
bassus
bassus16h ago
Call setVisible last
CADAN
CADANOP16h ago
alright it seems fixed thx again
bassus
bassus16h ago
Gimme Swing-Expert role xD Or call it Swinger 😏
CADAN
CADANOP16h ago
hahah
JavaBot
JavaBot11h ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?