java在复选框上添加鼠标拖动侦听器
每次用户尝试拖动复选框并将其从一个面板粘贴到另一个面板时,我都需要执行一些操作。 我知道Java提供拖放API,但我并不希望复选框从一个面板拖到另一个面板。 我想要的是给用户一种拖放的错觉,在幕后我想要我的代码运行并执行某些操作。我该怎么做
现在,当我将复选框image1从panelleft拖放到panel_right时,我希望在用户的拖放操作的后台运行某些代码
for(ResourceListObject currentImage : imageList ){
imageOnRepositoryCheckBox[checkBoxNumber] = new JCheckBox(currentImage.getName());
imageOnRepositoryCheckBox[checkBoxNumber].setBounds(6, gapping+checkBoxNumber*26, 368, 23);
imageOnRepositoryCheckBox[checkBoxNumber].setTransferHandler(new FromTransferHandler());
if(imagesToBeImported != null){
if(imagesToBeImported.contains(currentImage)){
imageOnRepositoryCheckBox[checkBoxNumber].setForeground(Color.GRAY);
imageOnRepositoryCheckBox[checkBoxNumber].setToolTipText("This image is already on the list of images to be imported and can't be selected again.");
}
}
panel.add(imageOnRepositoryCheckBox[checkBoxNumber]);
checkBoxNumber++;
}
第二段代码是
for(JCheckBox currentCheckBox : imageOnRepositoryCheckBox){
if(currentCheckBox.isSelected()){
Iterator itr = imagesOfCurrentRepository.iterator();
while(itr.hasNext()) {
ResourceListObject iteratedImage = (ResourceListObject)itr.next();
if(iteratedImage.getName().equals(currentCheckBox.getText())){
boolean isAdded = imagesToBeImported.add(iteratedImage);
descriptionPanel.updateDescription("The image selected for importing is "+currentCheckBox.getText());
if(isAdded){
currentCheckBox.setForeground(Color.GRAY);
currentCheckBox.setToolTipText("This image is already on the list of images to be imported and can't be selected again.");
}
}
}
updateImagesToBeImportedPanel(panel_1, imagesToBeImported);
}
checkBoxNumber++;
}
因此,我希望用户将其视为拖放,但在后端,我会做自己的事情
共 (0) 个答案