2014-02-07 27 views
2

//這裏是一個面板位於一個框架作爲第二個選項卡上我想添加一個滾動條。如何將滾動條添加到JTabbedPane。基本上我有一個管理面板作爲TAB(JTabbedPane)

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. 




} 
} 

//我認爲這是沒有必要的。

+0

我已經得到了我的用戶PEESKILLET的幫忙解答。 :D 我認爲這足以描述我的問題。 – puprog

+1

對我來說似乎是一個非常明確的問題......! :) – Droj

回答

6

「如何將滾動條添加到JTabbedPane的。基本上,我有進一步附着在框架上的TAB(JTabbedPane中)的管理面板」

基本上,你。您纏繞JScollPaneJPanel周圍被添加到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"); 

enter image description here

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); 
      } 
     }); 
    } 
}