This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Calculator Programming subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. General Coding and Design => Calculator Programming
Author Message
Arcane Wizard
`semi-hippie`


Super Elite (Last Title)


Joined: 02 Jun 2003
Posts: 8993

Posted: 03 May 2005 03:06:22 pm    Post subject:

I'm working on a task management tool and the GUI currently looks like this, on the left is a JScrollPane containing a "TaskTree" (extends JTree), and on the right is a simple empty JPanel I'll refer to as "contentPanel".

For a summary, read this line:
I want the user to be able to select a Task from the TaskTree and see the corresponding form in the contentPanel, this needs to be so dynamic that I must be able to replace the JPanel with one stored in the Task.

Now, I have a "Task" class that extends DefaultMutableTreeNode, which basically is just a DefaultMutableTreeNode with a JPanel stored in it as well. Since the Tasks are loaded into the TaskTree from that Task class, the TaskTree can access the JPanel stored in such a Task. I assigned a TreeSelectionListener to TaskTree, and it catches events in the tree correctly.

So what I want to do in the event of the user clicking on a Task is that the TreeSelectionListener replaces the contentPanel with the JPanel stored in that Task.

Now, it can access that JPanel just fine, I can get all it's properties and show them in the console from within the TreeSelectionListener. It can also access the contentPanel and change it's background color for example.

this one:
So, in order to replace contentPanel with the Task's JPanel, I simply do:
contentPanel = task.getPanel();

So now contentPanel points to the JPanel stored in the Task. This works correctly so far, since showing contentPanel's properties now shows the properties of the JPanel I replaced it with.

And the rest:
However, on the screen, nothing seems to happen. I think this is because the contentPanel isn't refreshed as it would be when I where to change the background colour (which works, and yes, I can change contentPanel's background colour to the background colour of Task's JPanel) and I know one would normally use [url="http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JComponent.html#revalidate()"]revalidate()[/url] to refresh a JPanel after adding a Button for example.

However, revalidate() does not seem to help, so I was wondering if anybody here could.

Never mind, I figured it out. Removing it from it's parent and then adding the new one works, though I had tried that.
Container parent = contentPanel.getParent();
JPanel taskPanel = task.getPanel();
parent.remove( contentPanel );
parent.add( taskPanel );

Overkill in my honest opinion, but it's clean and it works.
contentPanel = taskPanel;


Last edited by Guest on 03 May 2005 05:27:28 pm; edited 1 time in total
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement