gpt4 book ai didi

java - 手动鼠标拖动调整包含 JScrollPane 的 JOptionPanel 的大小

转载 作者:行者123 更新时间:2023-12-01 08:01:28 24 4
gpt4 key购买 nike

我有一个 JScrollPane,它具有允许拖动文件的文件拖放功能。我使用 JOptionPanel.showConfirmDialog 调用 JScrollPane,因此有“确定”和“取消”按钮。我希望能够将鼠标放在窗口边缘并拖动以调整其大小。我研究了许多不同的方法,但大多数都涉及框架,并且其中没有 JOptionPanes 。我怎样才能做到这一点或制作一个带有确定和取消按钮(如 showConfirmDialog)的可调整大小的面板。

这是我的面板的功能:

public static List<String> displayFilePanel() {
// Declare return object
final List<String> listOfFiles = new ArrayList<String>();

// Create scrollable panel to hold file list
final JTextArea text = new JTextArea();
JScrollPane scrollPane = new JScrollPane(text);
text.setLineWrap(true);
text.setWrapStyleWord(true);
scrollPane.setPreferredSize( new Dimension( 800, 800 ) );


// Drag and drop feature
// Add each file to listofFiles
//new FileDrop( System.out, text, /*dragBorder,*/ new FileDrop.Listener() for debugging
new FileDrop( null, text, /*dragBorder,*/ new FileDrop.Listener()
{ public void filesDropped( java.io.File[] files )
{ for( int i = 0; i < files.length; i++ )
{ try
{
text.append( files[i].getCanonicalPath() + "\n" );
listOfFiles.add(files[i].getCanonicalPath());
} // end try
catch( java.io.IOException e ) {}
} // end for: through each dropped file
} // end filesDropped
}); // end FileDrop.Listener

int result = JOptionPane.showConfirmDialog(null, scrollPane, "Files To rename",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
//System.out.println(text.getText());
} else {
System.out.println("File Pane Cancelled");

//if Cancelled is pressed clear the listOfFiles so a blank list is returned
listOfFiles.clear();
}


return listOfFiles;
}

最佳答案

如图here ,您可以将 JOptionPane 添加到 JDialog,这是一个可调整大小的 top-level container 。完整的示例如 answer 所示。 .

JDialog dialog = new JDialog();
JOptionPane optPane = new JOptionPane();

dialog.add(optPane);

关于java - 手动鼠标拖动调整包含 JScrollPane 的 JOptionPanel 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25007303/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com