2011-07-20 114 views
0
public TaskGraphComponent(ProjectFrame proFrame,TaskGraphModel model, painter) { 
    this.proFrame = proFrame; 
    _painter = painter; 

    setModel(model); 
    _mouseHandler = new GraphMouseHandler(this); 
    _verticalScroll = new JScrollBar(JScrollBar.VERTICAL); 
    this.add(_verticalScroll, BorderLayout.EAST); 

    _verticalScroll.addAdjustmentListener(this); 
    _verticalScroll.setVisible(true); 
    _horizontalScroll = new JScrollBar(JScrollBar.HORIZONTAL); 
    add(_horizontalScroll, BorderLayout.SOUTH); 
    _horizontalScroll.addAdjustmentListener(this); 
    _horizontalScroll.setVisible(true); 
    setBorder(BorderFactory.createEmptyBorder(0,0,15,0)); 
    this.addMouseMotionListener(_mouseHandler); 
    this.addMouseListener(_mouseHandler); 
    this.addMouseWheelListener(_mouseHandler); 
    this.addKeyListener(_mouseHandler); 
    this.addComponentListener(this); 
    this.setFocusable(false); 
    ToolTipManager.sharedInstance().setDismissDelay(8000); 
    ToolTipManager.sharedInstance().setReshowDelay(3000); 

}  

我從擴展JComponent的這裏垂直滾動條工作正常,但水平 滾動沒有顯示。揮杆水平滾動條問題

這裏TaskGraphComponent的是Jcomponent

+0

試試這個[示例](http://www.java2s.com/Code/Java/Swing-JFC/AquickdemonstrationofJScrollBarbothverticalandhorizo​​ntal.htm)。 –

+0

@Asad拉希德其實我累了信息存在聯繫,但同樣的問題 – Ganesh

+0

什麼是,似乎你不使用的佈局? –

回答

0

我測試此代碼,請運行它,並讓我知道。我的代碼更改從上面的鏈接: http://www.java2s.com/Code/Java/Swing-JFC/AquickdemonstrationofJScrollBarbothverticalandhorizontal.htm

import java.awt.BorderLayout; 
import java.awt.event.AdjustmentEvent; 
import java.awt.event.AdjustmentListener; 

import javax.swing.JComponent; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JScrollBar; 

public class SwingScrollBarExample extends JComponent implements AdjustmentListener { 

    JLabel label; 

    public SwingScrollBarExample() { 
    label = new JLabel(); 
    setLayout(new BorderLayout()); 

    JScrollBar _verticalScroll = new JScrollBar(JScrollBar.VERTICAL); 
    this.add(_verticalScroll); 

    _verticalScroll.addAdjustmentListener(this); 
    _verticalScroll.setVisible(true); 

    JScrollBar _horizontalScroll = new JScrollBar(JScrollBar.HORIZONTAL); 
    this.add(_horizontalScroll); 

    _horizontalScroll.addAdjustmentListener(this); 
    _horizontalScroll.setVisible(true); 

    this.add(_verticalScroll, BorderLayout.EAST); 
    this.add(_horizontalScroll, BorderLayout.SOUTH); 
    } 

    public void adjustmentValueChanged(AdjustmentEvent e) { 
     label.setText(" New Value is " + e.getValue() + "  "); 
     repaint(); 
    } 

    public static void main(String s[]) { 
    JFrame frame = new JFrame("Scroll Bar Example"); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    frame.setContentPane(new SwingScrollBarExample()); 
    frame.setSize(200, 200); 
    frame.setVisible(true); 
    } 
} 
+0

當我使用此代碼它顯示_verticalScroll.setMaximum(canScrollUp + canScrollDown)nullpointer期望 – Ganesh

+1

@Ganesh:什麼是** canScrollUp + scanScrollDown ** ,是指這些變量中的值是什麼? –

1

..not使用任何佈局..

這就是問題所在。 使用的佈局。