How to replace contents of a panel
[email protected] 08 Mar 2005 19:43:11 -0800
| Newsgroups | gmane.comp.embedded.carlsbad-cubes |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I have created a GUI application frame with a border layout. I am
trying to replace the panel that was is in the "center" of the frame's
border layout depending on which button I press in a toolbar.
I am able to initally render the GUI without any problems. I am using
actionCommands for the buttons, and I'm not having any problem detecting
which button is pressed.
I also don't have any problem finding the panel that I want it's
contents to be replaced with. My problems start when I try to replace
the contents of the panel.
This is the line of code that obtains the panel...
savedPanel = (JPanel)getEngine().find("application_panel");
This is the code I'm using to insert GUI components into the
savedPanel....
savedPanel.removeAll();
try {
getEngine().insert("guixml/dnssplitpane.xml", savedPanel);
savedPanel.repaint();
}
catch(Exception ex) {
ex.printStackTrace();
}
Replacing the contents within a panel seems to be a fairly common task.
A more classic example would be a split pane with a tree on the left and
a panel on the right. The contents of the panel on the right would
change depending on which node in the tree was selected. One selected
node might result in a table being displayed in the right panel, while
selecting another node might result in a set of editable text fields,
etc...
Any pointers, tips, or existing examples would be greatly appreciated.
This is the main panel.....
<panel id="DNS_MAIN_PANEL"
layout="BorderLayout"
constraints="BorderLayout.CENTER">
<panel id="pnl_North"
layout="borderlayout"
constraints="BorderLayout.NORTH">
<toolbar id="tb"
floatable="true"
borderPainted="true"
orientation="HORIZONTAL"
layout="BorderLayout">
<panel constraints="BorderLayout.CENTER" background="white"/>
<panel constraints="BorderLayout.EAST"
background="white"
layout="FlowLayout">
<button id="manage_btn"
ToolTipText="Management"
text="Management"
focusPainted="false"
enabled="true"
icon="icons/new.gif"
ActionCommand="manageAction"/>
<separator/>
<separator/>
<button id="monitor_btn"
ToolTipText="Monitoring"
text="Monitoring"
defaultCapable="false"
focusPainted="false"
enabled="true"
icon="icons/help.gif"
ActionCommand="monitorAction"/>
<separator/>
<separator/>
<button id="admin_btn"
ToolTipText="Administration"
text="Administration"
focusPainted="false"
selected="true"
enabled="true"
icon="icons/exit.gif"
ActionCommand="adminAction"/>
<separator/>
<separator/>
</panel>
</toolbar>
</panel>
<panel id="application_panel"
layout="Borderlayout"
constraints="BorderLayout.CENTER"
</panel>
</panel>
This is the panel I'm trying to insert into "application_panel"
<?xml version="1.0" encoding="UTF-8"?>
<panel constraints="BorderLayout.CENTER"
background="green"
layout="BorderLayout"
id="PNL_SPLIT_PANE">
<splitpane
constraints="BorderLayout.CENTER"
dividerlocation="400"
onetouchexpandable="true">
<tabbedpane titles="ID Grid,Administrators">
<panel layout="BorderLayout">
<scrollpane>
<tree showsroothandles="true"
selectionmode="1"
selectionrow="0"
backgroundcolor="white"
id="idgridtree"
initclass="com.infoblox.gui.model.IdOneTreeModel">
</tree>
</scrollpane>
</panel>
<panel layout="GridLayout(1,0)">
<scrollpane>
<table id="tbl" initclass="DNSTableModel">
</table>
</scrollpane>
</panel>
</tabbedpane>
<scrollpane HorizontalScrollBarPolicy="32"
VerticalScrollBarPolicy="22">
</scrollpane>
</splitpane>
</panel>