この JList にはカスタム コードが ActionMapAction を使用しています。カスタムの上下矢印ボタンを使用できるようになりましたが、マウスのスクロールを使用して jLIST を上下にスクロールすることはできません。
マウスのスクロールを実装して JList を上下にスクロールするにはどうすればよいですか?
jlist.setFont(new Font("Calibri",Font.BOLD,16));
jlist.setCellRenderer(new Renderer());
jlist.setFixedCellWidth(100);
jlist.setBorder(new EmptyBorder(10,10, 10, 10));
jlist.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent arg0) {
}
public void mouseEntered(MouseEvent arg0) {
}
public void mouseExited(MouseEvent arg0) {
}
public void mousePressed(MouseEvent e) {
JList<String> jl = (JList<String>)e.getSource();
if(e.getClickCount() == 2){
jlist.setCellRenderer(new Renderer(true));
int index = jl.locationToIndex(e.getPoint());
new OneToOneChat(jlist.getModel().getElementAt(index).toString());
System.out.print(index);
}
}
public void mouseReleased(MouseEvent e) {
jlist.setCellRenderer(new Renderer(false));
}
});
jsp = new JScrollPane(jlist);
jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
JScrollBar customScroll = jsp.getVerticalScrollBar();
add(jsp);
BasicArrowButton top = new BasicArrowButton(BasicArrowButton.TOP);
top.setAction(new ActionMapAction("", customScroll, "negativeUnitIncrement") );
add(top,BorderLayout.NORTH);
BasicArrowButton bottom = new BasicArrowButton(BasicArrowButton.SOUTH);
bottom.setAction(new ActionMapAction("", customScroll, "positiveUnitIncrement") );
add(bottom,BorderLayout.SOUTH);
}