Trouble with refreshing and deleting data in JPanels


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Trouble with refreshing and deleting data in JPanels

Hybrid View

  1. #1
    Join Date
    Jul 2010
    Posts
    1

    Trouble with refreshing and deleting data in JPanels

    I'm learning how to use Java Swing and tried my hand at creating a calendar or day planner. Essentialy i have a vector that store Detail objects, each object containing an hour, minute and text field, with the ability to activate it. I have a JPanel that is used to add new objects to the vector, but how do i refresh the JPanel or JFrame to show the new entry (i know the vector will not store the new entry when i close and reopen the app, i already have plans to serialize the vector). The other problem i have is that each entry has a delete button associated to it, but i can't get that to delete the entry, even though i've made the index a global variable. Eventually i will need to be able to do the same with the checkbox, where i can turn it off so the entry is invisible. The code i have is below:
    Attached Files Attached Files

  2. #2
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    Here are some debugging clues:
    Add a println() to show the value of row after you have added it. You'll need that later.
    allDetails.add(row);
    System.out.println("row=" + row); // show value of row

    In the delete button listener add these:
    class DelButtonListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    Component obj = (Component)e.getSource();
    Component parent = obj.getParent();
    System.out.println("Deleting " + obj + "\n p=" + parent + "\n gp=" + parent.getParent());

    If you delete by index, the indexes of the following rows change by -1. You need to find a reference to the object to be deleted and delete using that. The println()s I've given you should allow you to get the references to the objects to be deleted.

    After you remove components from the GUI display, you'll need to call validate() on one of the containers to have the GUI refreshed to show the removal.
    Last edited by Norm; 08-05-2010 at 03:01 PM.

Similar Threads

  1. refreshing data in a Datagrid with an ADO control
    By Fabio Quadrana in forum VB Classic
    Replies: 2
    Last Post: 01-20-2001, 02:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center