How to Add a scroll bar to a JTabbedPane. Basically i have an admin panel which is attached further on a frame as a TAB(JTabbedPane)
java, jframe, jpanel, jtabbedpane, swing
Solution
"How to Add a scroll bar to a JTabbedPane. Basically i have an admin panel which is attached further on a frame as a TAB(JTabbedPane)"
Basically, you don't. You wrap the `JScollPane` around the `JPanel` that is added to the `JTabbedPane`
JTabbedPane tabbed = new JTabbedPane();
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
tabbed.add(new JScrollPane(panel1), "Panel 1");
tabbed.add(new JScrollPane(panel2), "Panel 2");
import java.awt.*;
import javax.swing.*;
public class TestTabbedScroll {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run() {
JPanel panel = new JPanel();
Box box = Box.createVerticalBox();
for (int i = 0; i < 100; i++) {
box.add(new JLabel("Hello, StackOverflow!"));
}
panel.add(box);
panel.setBackground(Color.CYAN);
JTabbedPane tab = new JTabbedPane();
JScrollPane scroll = new JScrollPane(panel);
scroll.setPreferredSize(new Dimension(300, 300));
tab.add(scroll, "Panel 1");
JOptionPane.showMessageDialog(
null, tab, "Test Tabbed", JOptionPane.PLAIN_MESSAGE);
}
});
}
}
Problem
//here admin is a panel located on a frame as 2nd TAB on which i want to add a Scroll bar. ``` import java.awt.Color; import java.awt.Image; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollBar; import javax.swing.JScrollPane; public class admin extends JPanel { private static final long serialVersionUID = 1L; JLabel lb; Image image; JScrollPane js; public admin() //admin panel is invoked by a frame. { setBackground(Color.white); add(new admsign()); // admsign is another panel located on admin which is a simple form. // if you want me to post the code for admsign() then tell me. } } ``` // i think it is unnecessary.