I am trying to make a custom chat dialogue window for my instant messenger program. The dialogue is made of a separate class with a JFrame and a couple extra properties. I can create the JFrame and several components (a send message button, a text field for typing the message, and the scrollpane which is supposed to contain my JTextPane). Unfortunately, the JTextPane won't show up, only a grey box where the scrollpane is (I'm assuming that's what it is).
Here is the code for my custom dialogue window. package instantmessenger;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.text.Document;
public class ChatDialogue extends JComponent{
private BuddyConversation owner;
/** COMPONENTS *****************************/
private JFrame window;
private javax.swing.JButton btnSendMessage;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextPane textMessages;
private javax.swing.JTextField textNewMessage;
/*******************************************/
public ChatDialogue(String username, BuddyConversation owner){
this.owner = owner;
initComponents(username);
}
private void btnSendMessageActionPerformed(java.awt.event.ActionEvent evt){
owner.addMessage(textNewMessage.getText());
}
public javax.swing.JTextPane getMessageBox(){
return textMessages;
}
private void initComponents(String toUser){
window = new JFrame();
window.setAlwaysOnTop(true);
window.setBounds(new java.awt.Rectangle(0, 0, 200, 400));
window.setMaximizedBounds(new java.awt.Rectangle(0, 0, 200, 12312312));
window.setMaximumSize(new java.awt.Dimension(200, 12312312));
window.setMinimumSize(new java.awt.Dimension(200, 375));
window.setTitle("Chat with " + toUser);
textMessages = new javax.swing.JTextPane();
jScrollPane1 = new javax.swing.JScrollPane(textMessages);
jLabel1 = new javax.swing.JLabel();
textNewMessage = new javax.swing.JTextField();
btnSendMessage = new javax.swing.JButton();
javax.swing.GroupLayout windowLayout = new javax.swing.GroupLayout(window.getContentPane());
window.getContentPane().setLayout(windowLayout);
windowLayout.setHorizontalGroup(
windowLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(windowLayout.createSequentialGroup()
.addContainerGap()
.addGroup(windowLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1)
.addComponent(textNewMessage)
.addGroup(windowLayout.createSequentialGroup()
.addGroup(windowLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(btnSendMessage))
.addGap(0, 29, Short.MAX_VALUE)))
.addContainerGap())
);
windowLayout.setVerticalGroup(
windowLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(windowLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(textNewMessage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnSendMessage)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
btnSendMessage.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSendMessageActionPerformed(evt);
}
});
/** ADD COMPONENTS TO JFRAME ******************************************/
//window.getContentPane().add(jLabel1);
//window.getContentPane().add(jScrollPane1);
//window.getContentPane().add(textNewMessage);
//window.getContentPane().add(btnSendMessage);
//window.add(textMessages);
/**********************************************************************/
jScrollPane1.setViewportView(textMessages);
jLabel1.setText("Put your message her and then hit enter or something or press the button");
btnSendMessage.setText("Send Message");
jScrollPane1.setVisible(true);
textMessages.setVisible(true);
window.invalidate();
window.repaint();
window.pack();
window.revalidate();
window.setVisible(true);
}
}
So right now as I said before the only thing that shows up is a grey outline where the text and scrollpane should go. I made the JFrame design in the design editor in my main GUI and then just copy and pasted the autogenerated code into my custom class...
The code at the bottom is just me messing around trying to get it to work. I could have probably switched it to a normal textfield or something and gotten it to work but I can't stand not knowing what I'm doing wrong. Help would be much appreciated.