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
JavaBot3mo 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
bassus3mo 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
JavaBot3mo 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
CADANOP3mo 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
bassus3mo 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
CADANOP3mo ago
yes exactly
CADAN
CADANOP3mo ago
there is it
No description
bassus
bassus3mo 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
CADANOP3mo ago
ok, take your time ty
bassus
bassus3mo ago
Like it depends a bit. Are those to do items just strings? Like, is that enough?
CADAN
CADANOP3mo ago
Actually It came pre-established like that, I havent touched it im trying rn to integrate the JPanels to the JForm
CADAN
CADANOP3mo ago
but it doesn't let me modify the part of the code that is underlined in yellow
No description
CADAN
CADANOP3mo ago
bc im doing it with the Java graphical editor
No description
bassus
bassus3mo ago
what? with netbeans?
CADAN
CADANOP3mo ago
yes with neatbeans
bassus
bassus3mo 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
CADANOP3mo ago
😶 why is an atrocity?
Madjosz
Madjosz3mo ago
Oh, Netbeans is still including the full-qualified class name in the generated code?
bassus
bassus3mo 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
CADANOP3mo 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
bassus3mo ago
Yeah bro, that was no attack on you. Sry if i offended you^^
CADAN
CADANOP3mo 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
Madjosz3mo ago
This is just generated code by Netbeans. You won't clean it up.
bassus
bassus3mo 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
CADANOP3mo 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
bassus3mo ago
Bro, i want to really do bad things to the developers of NetBeans. Biggest crime against good code ever committed ._.
Madjosz
Madjosz3mo ago
Every generated code is the biggest crime against best practice code.
bassus
bassus3mo 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
CADANOP3mo ago
I can try with IntellJ, but idk how to use it
bassus
bassus3mo ago
Deal
ayylmao123xdd
ayylmao123xdd3mo ago
lombok is amazing 😤
CADAN
CADANOP3mo ago
😿 ok I understood, but I blame my teacher for teaching me like that
bassus
bassus3mo ago
Yeah, your teacher is not a good coder. Not your fault
Madjosz
Madjosz3mo ago
I am not saying you shouldn't use it. Just don't expect the generated code to look good.
ayylmao123xdd
ayylmao123xdd3mo ago
maybe thats just how he has to teach depends
Madjosz
Madjosz3mo ago
Nah, you need a compiler plugin for it.
CADAN
CADANOP3mo 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
ayylmao123xdd3mo ago
a single getter looks better than 20 get methods
bassus
bassus3mo ago
Lol, what a noob^^
ayylmao123xdd
ayylmao123xdd3mo ago
is this university or high school
CADAN
CADANOP3mo ago
unfortunately university
ayylmao123xdd
ayylmao123xdd3mo ago
interesting looks like he just doesnt care
CADAN
CADANOP3mo 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
ayylmao123xdd3mo ago
well boring stuff aside do you want the data to save between switching pages or between application startup
CADAN
CADANOP3mo ago
for now between switching pages Later between the applicaction startup
CADAN
CADANOP3mo ago
ok now what
No description
bassus
bassus3mo ago
Bro, what should the volver button even do?
CADAN
CADANOP3mo ago
go to the principal menu and theres where the problem started
bassus
bassus3mo ago
Uhm there is a principal menu?
CADAN
CADANOP3mo ago
well yeah for the dashboard of the list?
ayylmao123xdd
ayylmao123xdd3mo ago
so like when u go to the menu
bassus
bassus3mo ago
What do you mean by dashboard of the list? What does it look like?
ayylmao123xdd
ayylmao123xdd3mo ago
and u go back to the list
CADAN
CADANOP3mo ago
is like this
No description
ayylmao123xdd
ayylmao123xdd3mo ago
the stuff in the list disappears
CADAN
CADANOP3mo ago
thats like the dashboard
CADAN
CADANOP3mo ago
and this was going to be like the other window
No description
CADAN
CADANOP3mo ago
for the user to put his tasks
bassus
bassus3mo ago
This will be the JFrame this will be a JDialog
CADAN
CADANOP3mo 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
ayylmao123xdd3mo ago
ummmm like you got a bunch of objects
bassus
bassus3mo ago
You normally would do this in a 3-layered architecture
ayylmao123xdd
ayylmao123xdd3mo ago
and for each object show them in a list
CADAN
CADANOP3mo ago
yes sm like that
ayylmao123xdd
ayylmao123xdd3mo ago
oh ok
CADAN
CADANOP3mo ago
ok
ayylmao123xdd
ayylmao123xdd3mo ago
do you have adding to list already implemented like to the object
CADAN
CADANOP3mo ago
and how it would be, like we were talking, one JFrame and two JPanel or what yes
ayylmao123xdd
ayylmao123xdd3mo ago
so whats the problem cuz like idk what it is lmao
CADAN
CADANOP3mo ago
this is where it Storages,
No description
No description
No description
ayylmao123xdd
ayylmao123xdd3mo ago
yes
CADAN
CADANOP3mo ago
yes but idk how to show like those clases in a graphic way
ayylmao123xdd
ayylmao123xdd3mo ago
oh
CADAN
CADANOP3mo ago
thats why im seeking help with java swing IDK how it works 💀
ayylmao123xdd
ayylmao123xdd3mo ago
so whats in storage show on gui yes or no @bassus you know swing or no
bassus
bassus3mo ago
I do But i'm currently still reading up on it, it's been a year since i last used it^^
ayylmao123xdd
ayylmao123xdd3mo ago
great this item1 item2 you added manually right not through code
bassus
bassus3mo ago
I know how to make it work, i don't know, how to make it pretty 😄
CADAN
CADANOP3mo ago
It generated like that
ayylmao123xdd
ayylmao123xdd3mo ago
ok
ayylmao123xdd
ayylmao123xdd3mo 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
ayylmao123xdd3mo 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
ayylmao123xdd3mo ago
check these out
CADAN
CADANOP3mo 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
ayylmao123xdd3mo ago
idk swing so i can only send links lol
CADAN
CADANOP3mo ago
ty
bassus
bassus3mo ago
okay Cadan
bassus
bassus3mo ago
A very basic way to organize your fun
bassus
bassus3mo 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
CADANOP3mo ago
right thanks im also changing to INTELLJ
CADAN
CADANOP3mo ago
better? aslkdj
No description
bassus
bassus3mo ago
Why is there a JFrame field? private JFrame frame;?
bassus
bassus3mo 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
CADANOP3mo ago
you're right, I'm overwriting it. so, so
bassus
bassus3mo ago
No, you alread have a JFrame here. It's called this
CADAN
CADANOP3mo ago
yea sorry
bassus
bassus3mo ago
Stop apologizing, all good^^
CADAN
CADANOP3mo ago
No description
CADAN
CADANOP3mo ago
🫡
CADAN
CADANOP3mo 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
bassus3mo ago
Uhm What
ayylmao123xdd
ayylmao123xdd3mo ago
maybe you are running a different file
CADAN
CADANOP3mo ago
idk is just that when I run the program sometimes it appears right, then I again excecute it and appears empty
bassus
bassus3mo ago
Call setVisible last
CADAN
CADANOP3mo ago
alright it seems fixed thx again
bassus
bassus3mo ago
Gimme Swing-Expert role xD Or call it Swinger 😏
CADAN
CADANOP3mo ago
hahah
JavaBot
JavaBot3mo 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?