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
⌛
This post has been reserved for your question.
Hey @CADAN! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose 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.
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^^
💤
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.
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
😿
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.
yes
exactly
there is it

Yeah
For that you will need JPanels, JList and JDialog. I have to read up though, how exactly you used them, gimme a second^^
ok, take your time ty
Like it depends a bit. Are those to do items just strings?
Like, is that enough?
Actually It came pre-established like that, I havent touched it
im trying rn to integrate the JPanels to the JForm
but it doesn't let me modify the part of the code that is underlined in yellow

bc im doing it with the Java graphical editor

what? with netbeans?
yes with neatbeans
Sry, but i won't help you building atrocities against best practice. The code in the screenshot is already violating style guidelines, sry.
😶 why is an atrocity?
Oh, Netbeans is still including the full-qualified class name in the generated code?
Already the first line:
You should write:
dude im new into coding, I just want to guide my project well thats why I entered in this discord server to seek help
Yeah bro, that was no attack on you. Sry if i offended you^^
: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
This is just generated code by Netbeans. You won't clean it up.
I'm just saying, pls don't use NetBeans Graphical Editor for Swing. Use Eclipse, IntelliJ, VSC, whatever and i gladly will help you 😄
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
Bro, i want to really do bad things to the developers of NetBeans. Biggest crime against good code ever committed ._.
Every generated code is the biggest crime against best practice code.
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.
I can try with IntellJ, but idk how to use it
Deal
lombok is amazing 😤
😿 ok I understood, but I blame my teacher for teaching me like that
Yeah, your teacher is not a good coder.
Not your fault
I am not saying you shouldn't use it. Just don't expect the generated code to look good.
maybe thats just how he has to teach
depends
Nah, you need a compiler plugin for it.
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
a single getter looks better than 20 get methods
Lol, what a noob^^
is this university or high school
unfortunately university
interesting
looks like he just doesnt care
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
well
boring stuff aside
do you want the data to save between switching pages
or between application startup
for now between switching pages
Later between the applicaction startup
ok now what

Bro, what should the volver button even do?
go to the principal menu
and theres where the problem started
Uhm there is a principal menu?
well yeah for the dashboard of the list?
so like
when u go to the menu
What do you mean by dashboard of the list? What does it look like?
and u go back to the list
is like this

the stuff in the list disappears
thats like the dashboard
and this was going to be like the other window

for the user to put his tasks
This will be the JFrame
this will be a JDialog
thats what im trying to figure out, how to save the information in a class, how to show them in a graphic context
ummmm
like you got a bunch of objects
You normally would do this in a 3-layered architecture
and for each object show them in a list
yes sm like that
oh
ok
ok
do you have adding to list already implemented
like to the object
and how it would be, like we were talking, one JFrame and two JPanel
or what
yes
so whats the problem cuz like
idk what it is lmao
this is where it Storages,



yes
yes but idk how to show like those clases in a graphic way
oh
thats why im seeking help with java swing
IDK how it works
💀
so whats in storage
show on gui
yes or no
@bassus you know swing or no
I do
But i'm currently still reading up on it, it's been a year since i last used it^^
great
this item1 item2 you added manually right
not through code
I know how to make it work, i don't know, how to make it pretty 😄
It generated like that
ok
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...
How to Use Lists (The Java™ Tutorials >
Creat...
Creat...
This Swing Java Tutorial describes developing graphical user interfaces (GUIs) for applications and applets using Swing components
check these out
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
idk swing so i can only send links lol
ty
okay
Cadan
A very basic way to organize your fun
@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 goofyright thanks
im also changing to INTELLJ
better? aslkdj

Why is there a JFrame field?
private JFrame frame;
?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
you're right, I'm overwriting it.
so, so
No, you alread have a JFrame here. It's called
this
yea sorry
Stop apologizing, all good^^

🫡
one more question, anyone knows why in IntellJ the Run sometimes works and when I excecute it again it appears like this


Uhm
What
maybe you are running a different file
idk is just that when I run the program sometimes it appears right, then I again excecute it and appears empty
Call setVisible last
alright
it seems fixed
thx again
Gimme Swing-Expert role xD
Or call it Swinger 😏
hahah
💤
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.