Here’s my test program. I want to have three panels. One panel is the main panel and it has two subpanels. The chat panel and the button Panel. I use BorderLayout. At first I didn’t set any sizes because I thought the componenets would all expand to the right size, but that didn’t work. I explicitly set the sizes of everything below and that still doesn’t work.
import java.awt.*;
import java.awt.event.*;
import com.xith3d.scenegraph.*;
import com.xith3d.render.*;
import com.xith3d.render.jogl.*;
import javax.vecmath.*;
import javax.swing.*;
import com.xith3d.userinterface.*;
public class TryUI{
UIWindowManager windowMgr;
View view;
String inputText = "";
public void start(){
while(true){
view.renderOnce();
}
}
public void init() throws Exception
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
VirtualUniverse universe = new VirtualUniverse();
view = new View();
view.setBackClipDistance(100f);
view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
view.getTransform().lookAt(new Vector3f(0, 0, 3), new Vector3f(0, 0, 0), new Vector3f(0, 1, 3));
Locale locale = new Locale();
universe.addLocale(locale);
universe.addView(view);
RenderPeer renderPeer = new RenderPeerImpl();
CanvasPeer canvasPeer = renderPeer.makeCanvas(null,
screenSize.width - 200,
screenSize.height - 200,
16, false);
canvasPeer.getWindow().setLocation(100, 100);
Canvas3D canvas = new Canvas3D();
canvas.set3DPeer(canvasPeer);
view.addCanvas3D(canvas);
// construct a window manager for this canvas
windowMgr = new UIWindowManager(canvas);
TestWindow w = new TestWindow(800,200);
windowMgr.addOverlay(w);
windowMgr.setPosition(w,25,600);
windowMgr.setVisible(w,true);
UIEventAdapter eventAdapter = new UIEventAdapter(windowMgr);
canvas.get3DPeer().getComponent().addKeyListener(eventAdapter);
canvas.get3DPeer().getComponent().addMouseListener(eventAdapter);
canvas.get3DPeer().getComponent().addMouseMotionListener(eventAdapter);
canvas.get3DPeer().getComponent().setFocusable(true);
start();
}
class TestWindow extends UIWindow{
public TestWindow(int width, int height) {
super(width, height, false, false );
setRoot(buildGUI(width,height));
this.pack();
}
private JComponent buildGUI (int width, int height) {
JPanel mainPanel = new JPanel();
JPanel chatPanel = new JPanel();
JPanel buttonPanel = new JPanel();
mainPanel.setDoubleBuffered(true);
mainPanel.setLocation(0,0);
mainPanel.setBackground(new Color(1.0f,1.0f,1.0f,0.5f)); //the 4th parameter changes the transparency setting
//TextArea
final JTextArea textAreaScreen = new JTextArea();
textAreaScreen.setEditable(false);
textAreaScreen.setBackground(new Color(1f,1f,1f,.5f));
textAreaScreen.setLineWrap(true);
//ScrollPane
final JScrollPane scrollPaneScreen = new JScrollPane(textAreaScreen);
scrollPaneScreen.setBackground(new Color(1f,1f,1f, 0.5f));
scrollPaneScreen.setSize(width, 100);
scrollPaneScreen.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
scrollPaneScreen.repaint();
}
});
//TextField
final JTextField textFieldInput = new JTextField();
textFieldInput.setSize(width, 100);
textFieldInput.setBackground(new Color(1f,1f,1f,0.5f)); //the 4th parameter changes the transparency settings
textFieldInput.addKeyListener(new KeyListener(){
public void keyPressed(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e) {
if(e.getKeyChar() == 10){
textAreaScreen.append("\n" + textFieldInput.getText());
textFieldInput.setText("");
}
}
});
//Button
JButton logoutButton = new JButton();
logoutButton.setText("Logout");
logoutButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
//Set Panel and Component SIze
mainPanel.setSize(new Dimension(width,height));
chatPanel.setSize(new Dimension(width, height/2));
buttonPanel.setSize(new Dimension(width, height/2));
scrollPaneScreen.setSize(new Dimension(width, height/4));
textAreaScreen.setSize(new Dimension(width, height/4));
textFieldInput.setSize(new Dimension(width, height/4));
logoutButton.setSize(new Dimension(100,25));
chatPanel.add(scrollPaneScreen, BorderLayout.CENTER);
chatPanel.add(textFieldInput, BorderLayout.SOUTH);
buttonPanel.add(logoutButton, BorderLayout.SOUTH);
mainPanel.add(chatPanel, BorderLayout.CENTER);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
return mainPanel;
}
}
public static void main(String[] args)
{
try
{
TryUI test = new TryUI();
test.init();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
WHat could be causing the problem?