//这里的 admin 是一个位于框架上的面板,作为第二个 TAB,我想在上面添加一个滚动条。
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.
}
}
//我觉得没必要。
"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)"
基本上,您不会。您将 JScollPane
包裹在添加到 JTabbedPane
的
JPanel
周围
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);
}
});
}
}