[4408] in java-interest
Q : Removing components from panels
daemon@ATHENA.MIT.EDU (Kondratiev Dima)
Fri Dec 22 10:49:48 1995
From: Kondratiev Dima <DIMA@edge.paragraph.com>
To: Java Interest <java-interest@java.sun.com>
Date: Fri, 22 Dec 95 17:18:00 R
Thank's a lot for quick help on my psting "Beta 2 : Can't make Panels work"
from aim@scndprsn.Eng.Sun.COM and neudeck.arthur@ch.swissbank.com
My mistake was trivial, I noticed it as soon as posted my question. Sorry :(
Actually other problems with pannels made me
to turn to the mail-list that first time. After spending a lot
of time trying to figure out what is going on with Panels
I started to split my Gui in simple elements and implement
them step by step at a time. Late at night I came to
crazy idea that there is something wrong with Panels.
As a result - my previouse posting. May be the following is also a trivial
problem.
I am still trying to do the same thing : make applet window change its GUI
during runtime.
Adding TextArea and Button widgets to Panels work fine.
Then I add Label to infoPanel for ConversationGUI only.
I want this label to be displayed each time ConversationGUI is made.
First time ConversationGUI is shown as it should be.
But after switching to ConnectGUI and back, label
in ConversationGUI is never displayed again.
I tried to create panels only once, defining them as applet class instance
vars.
I used removeAll() to remove components from previouse view, but It didn't
help.
Please, enlighten me.
Thank you,
Dima.
-----------------------------------------------------------------------
import java.applet.Applet;
import java.awt.*;
//import java.awt.GridBagConstraints;
import java.util.*;
public class GuiTest extends java.applet.Applet {
String Welcome = "Hello !";
TextArea infoArea = new TextArea(Welcome, 5, 20);
TextArea inputArea = new TextArea(5,20);
Button connectButton = new Button("Connect");
public void init() {
addNotify();
//makeConnectGui();
makeConversationGui();
}
public boolean action(Event evt, Object arg) {
if(evt.target == connectButton) {
if(("Connect").equals(arg)) {
makeConnectGui();
connectButton.setLabel("Cancel");
infoArea.setText("Connecting....");
} else {
connectButton.setLabel("Connect");
infoArea.setText(Welcome);
makeConversationGui();
}
}
return true;
}
protected void makeConversationGui() {
//make conversation GUI
removeAll();
Panel infoPanel = new Panel();
Panel inputPanel = new Panel();
Panel controlPanel = new Panel();
//setLayout(new GridLayout(0, 1)); //rows - any nymber, cols - 1
setLayout(new BorderLayout());
add("North",infoPanel);
add("Center",inputPanel);
add("South",controlPanel);
/*
//This doesn't work
infoPanel.setLayout(new BorderLayout()); //------1
infoPanel.add("South",new Label("Info", Label.CENTER)); //------1
infoPanel.add("North",infoArea); //------1
*/
infoPanel.add(infoArea); //this works //-------2
inputPanel.add(inputArea);
controlPanel.add(connectButton);
layout();
}
protected void makeConnectGui() {
removeAll();
Panel infoPanel = new Panel();
Panel inputPanel = new Panel();
Panel controlPanel = new Panel();
infoPanel.add(infoArea);
inputPanel.add(inputArea);
controlPanel.add(connectButton);
setLayout(new BorderLayout());
add("North",controlPanel);
add("Center",inputPanel);
add("South",infoPanel );
layout();
}
}
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com