Reputation: 55
I am Working on Swing application and i need to add Dynamically Scroll pane into the Tabbed Pane and I need to add Jpanel into the each Scroll pane. so how can i add it i have tried one code but its not adding Scroll pane. can i have help.
Here my code is.
public class ChatDialog_Tabbedpane extends javax.swing.JFrame {
static JLabel jLabelchat;
int i= 0;
public ChatDialog_Tabbedpane() {
initComponents();
setVisible(true);
}
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
try {
System.out.println(jTextArea1.getText());
JScrollPane jsp = new JScrollPane();
JPanel jPanel = new JPanel();
jsp.add(jPanel);
jPanel.setLayout(new BoxLayout(jPanel, 1));
i++;
jPanel.add(new JLabel(i+" :label"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jPanel.add(new JLabel(i+" :label 2"));
jTabbedPane1.addTab("tab", jPanel);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ChatDialog_Tabbedpane().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration
}
its looking like this
but not showing scroll i just need to add all time That pane when Send button is clicked. and how can i get it using unique identify?
Upvotes: 0
Views: 671
Reputation: 347184
Don't use add
with JScrollPane
, use setViewportView
instead, for example...
jsp.setViewportView(jPanel);
See How to Use Scroll Panes for more details
A component may only reside within a single contaniner, when you do something like...
jTabbedPane1.addTab("tab", jPanel);
You are removing the jPanel
from it's previous parent (the JScrollPane
), instead, add the scroll pane to the tabbed pane...
jTabbedPane1.addTab("tab", jsp);
Upvotes: 1