如何在JFrame中使用JInternalFrame?
我想创建一个客户端/服务器应用程序.
我知道JInternalFrame应该与JDeskTopPane一起使用,但我想要一个可以在应用程序中移动的聊天窗口(就像在Facebook聊天一样).
>如何使用JInternalFrame?
>你为此推荐任何其他Swing组件吗?
最佳答案
以下是您正在寻找的简短工作示例.
码:
码:
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jInternalFrame1 = new javax.swing.JInternalFrame();
setDefaultCloSEOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jInternalFrame1.setBackground(new java.awt.Color(0,204));
jInternalFrame1.setBorder(javax.swing.BorderFactory.createMatteBorder(7,7,new java.awt.Color(0,0)));
jInternalFrame1.setTitle("This is JInternal Frame");
jInternalFrame1.setVisible(true);
javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
jInternalFrame1Layout.setHorizontalGroup(
jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0,386,Short.MAX_VALUE)
);
jInternalFrame1Layout.setVerticalGroup(
jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0,304,Short.MAX_VALUE)
);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jInternalFrame1)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jInternalFrame1)
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1,javax.swing.GroupLayout.DEFAULT_SIZE,Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1,javax.swing.GroupLayout.PREFERRED_SIZE,javax.swing.GroupLayout.PREFERRED_SIZE)
);
pack();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
private javax.swing.JInternalFrame jInternalFrame1;
private javax.swing.JPanel jPanel1;
}
有关更多信息,请参见How to Use Internal Frames
编辑:
P.S – 我已经接受了JPanel的帮助.如果您希望随时隐藏组件,
使用foo.setVisible(false)的setVisible(false).