#Deleted JPanel is still being drawn to the screen JSwing
1 messages · Page 1 of 1 (latest)
<@&987246487241105418> please have a look, thanks.
private void deletePanel(OrderLinePanel panel) {
JPanel currentJPanel = panel.getOrderLinePanel();
currentJPanel.removeAll();
remove(currentJPanel);
orderLinePanels.remove(panel);
revalidate();
repaint();
}
When I debug I can see the JPanel becomes null. But it remains on the screen
My program automatically adds to the 5 if you add the same one twice
but if you hit the delete button and try again
This happens
so when you debug, the list of components for your list container no longer has any components after deleting?
The panels list of components is empty
The problem is remove() doesn't delete it
but you said the component list is empty after deleting, yeah?
Yes
so deleting pushes the component to the center? im trying to piece together the story
or are you saying the gap above the new component is the old component that wont be removed?
and when you add a new panel, your container shows 2 components? or just 1?
when debugging
but when deleting, do they all still show up?
Yes
check the reference IDs within the debugger, see if currentPanel matches the ID of the components in your OrderLinePanel
yup
which means the panel you're getting from OrderLinePanel isn't actually one of the panels on the container
Why can I use removeAll on it then?
it could be that there's some intermediate panel
check the components of the panel you're trying to remove, see if that contains a JPanel
the currentJPanel may contain the panel you are trying to remove
It seems to be contained inside
hence why removeAll would remove the components (since its removing the panel), but can't be used to remove from the root container
But thats what its suppossed to
OrderLinePanel is a wrapper class i made for it
So I could link it with other variables to make it easier to code
the JPanel itself doesnt have a JPanel inside of it
is OrderLinePanel an actual JPanel?
No
package gui;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class OrderLinePanel {
private JPanel orderLinePanel;
private JTextField quantityField;
private String name;
private int quantity;
public OrderLinePanel(JPanel orderLinePanel, JTextField quantityField, String name, int quantity) {
this.orderLinePanel = orderLinePanel;
this.quantityField = quantityField;
this.name = name;
this.quantity = quantity;
}
public int getQuantity() {
return quantity;
}
public String getName() {
return name;
}
public JPanel getOrderLinePanel() {
return orderLinePanel;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
quantityField.setText(Integer.toString(quantity));
}
public void setName(String name) {
this.name = name;
}
}
The naming is a little confusing. I def need to fix it up
what im saying is check if the orderLinePanel (which you're trying to remove) has a parent or a JPanel child
whats the parent?
The parent is a another jpanel
so compare the IDs of all those panels, see which one matches the ID of the panel that's added to the list container
which one matches though?
before you said currentJPanel didnt have an ID that matched the panel added to the list
I took this screenshot before deleting
yeah, you'd look at the IDs before deleting, to make sure they match up
They are 100% the same
then what did you mean by this?
I must have misread it
Strange
They 100% have the correct ids
I have triple checked
@true echo ?
i'd have to check it out. all im seeing are pieces of the problem. i still believe that, based on the behavior of removeAll and remove you're seeing, that there is an intermediate panel that's causing trouble
im at work right now though, so it would have to be later, either during a break or when i get home
mind posting the whole project, via github or some other repo hosting site?
Unfortunately I'm unable to share the whole project
its school policy
But I can give you the source code for the entire class thats causing problems
you can just comment out any backend stuff
and add a main method
that should work, as long as the problem can be reproduced
Are you available rn?
I uploaded your attachments as Gist.
package gui;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class OrderLinePanel {
private JPanel orderLinePanel;
private JTextField quantityField;
private String name;
private int quantity;
public OrderLinePanel(JPanel orderLinePanel, JTextField quantityField, String name, int quantity) {
this.orderLinePanel = orderLinePanel;
this.quantityField = quantityField;
this.name = name;
this.quantity = quantity;
}
public int getQuantity() {
return quantity;
}
public String getName() {
return name;
}
public JPanel getOrderLinePanel() {
return orderLinePanel;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
quantityField.setText(Integer.toString(quantity));
}
public void setName(String name) {
this.name = name;
}
}
ill try it out tomorrow, assuming you havent found the problem already
Appreciate it.
@full osprey
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure 👍
.
still having problems?
ignore the message i wrote, i confused something with something lol
ill be home in about an hour, ill give it a look
@full osprey
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure 👍
so it seems you're adding the panels to centerOf0L, but you don't try removing from that panel
you instead try removing from the current instance
instead of remove(currentJPanel), you should remove it from the panel you added it to: centerOf0L.remove(currentJPanel)
Of course it was something super easy and simple.
I thought remove() worked on the jframe itself and not on each individual component
Works now, appreciate it