java右击删除_java – JList右键单击显示菜单(使用,删除,取消)

我不知道你想表达什么意思.这里的代码似乎与您指定的一样,但除了删除任何数量的冗余或错误语句之外,它几乎就是您发布的内容.

/*

*/

import java.awt.*;

import java.awt.event.MouseEvent;

import java.awt.event.MouseAdapter;

import javax.swing.*;

public class inv extends JApplet { //implements MouseListener {

JList listbox;

public void init()

{

String listData[] = { "Item 1","Item 2","Item 3","Item 4" };

listbox = new JList( listData );

listbox.addMouseListener( new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

System.out.println(e);

if ( SwingUtilities.isRightMouseButton(e) )

{

System.out.println("Row: " + getRow(e.getPoint()));

listbox.setSelectedIndex(getRow(e.getPoint()));

}

}

});

listbox.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

add(listbox);

// unnecessary

//listbox.setVisible(true);

listbox.setFocusable(false);

}

private int getRow(Point point)

{

return listbox.locationToIndex(point);

}

/** Why implement MouseListener, while adding a MouseAdapter?

Do you have ANY idea what your doing?

public void mousePressed(MouseEvent e) {

}

public void mouseReleased(MouseEvent e) {

}

public void mouseEntered(MouseEvent e) {

}

public void mouseExited(MouseEvent e) {

}

public void mouseClicked(MouseEvent e) {

}

*/

/** What is this nonsense supposed to achieve?

Don't override empty methods with empty implementations!

public void stop()

{

}

*/

/** What is this nonsense supposed to achieve?

public void paint(Graphics g)

{

}

*/

}

产量

java.awt.event.MouseEvent[MOUSE_PRESSED,(31,22),absolute(39,72),button=3,modifiers=Meta+Button3,extModifiers=Button3,clickCount=1] on javax.swing.JList[,0,0,200x200,alignmentX=0.0,alignmentY=0.0,border=,flags=50331944,maximumSize=,minimumSize=,preferredSize=,fixedCellHeight=-1,fixedCellWidth=-1,horizontalScrollIncrement=-1,selectionBackground=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],selectionForeground=sun.swing.PrintColorUIResource[r=51,g=51,b=51],visibleRowCount=8,layoutOrientation=0]

Row: 1

java.awt.event.MouseEvent[MOUSE_PRESSED,(29,39),absolute(37,89),button=3,modifiers=Meta+Button3,extModifiers=Button3,clickCount=1] on javax.swing.JList[,0,0,200x200,alignmentX=0.0,alignmentY=0.0,border=,flags=50331944,maximumSize=,minimumSize=,preferredSize=,fixedCellHeight=-1,fixedCellWidth=-1,horizontalScrollIncrement=-1,selectionBackground=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],selectionForeground=sun.swing.PrintColorUIResource[r=51,g=51,b=51],visibleRowCount=8,layoutOrientation=0]

Row: 2

java.awt.event.MouseEvent[MOUSE_PRESSED,(36,65),absolute(468,192),button=3,modifiers=Meta+Button3,extModifiers=Button3,clickCount=1] on javax.swing.JList[,0,0,200x200,alignmentX=0.0,alignmentY=0.0,border=,flags=50331944,maximumSize=,minimumSize=,preferredSize=,fixedCellHeight=-1,fixedCellWidth=-1,horizontalScrollIncrement=-1,selectionBackground=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],selectionForeground=sun.swing.PrintColorUIResource[r=51,g=51,b=51],visibleRowCount=8,layoutOrientation=0]

Row: 3

java.awt.event.MouseEvent[MOUSE_PRESSED,(45,11),absolute(477,138),button=3,modifiers=Meta+Button3,extModifiers=Button3,clickCount=1] on javax.swing.JList[,0,0,200x200,alignmentX=0.0,alignmentY=0.0,border=,flags=50331944,maximumSize=,minimumSize=,preferredSize=,fixedCellHeight=-1,fixedCellWidth=-1,horizontalScrollIncrement=-1,selectionBackground=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],selectionForeground=sun.swing.PrintColorUIResource[r=51,g=51,b=51],visibleRowCount=8,layoutOrientation=0]

Row: 0

Tool completed successfully

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值