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 :(得分:1)
..不使用任何布局..
这就是问题所在。 使用布局。
答案 1 :(得分: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);
}
}