英文:
How to determine row selected within jScrollPane
问题
我正在填充一个包含文件列表的jScrollPane(在JFrame Swing GUI中)。有没有办法确定用户在jScrollPane中点击了哪一行。我想要识别行,并提取用户选择的那一行的内容。
英文:
I am populating a jScrollPane (within a JFrame Swing GUI) with a list of files. Is there a way to determine which row the user has clicked on within jScrollPane. I want to identify the row and extract the contents of that row that the user selected.
答案1
得分: 1
你最好使用具有内置选择功能的JList或JTable。这里是JTable的Oracle文档基础部分。
我建议在初学时使用JTable与DefaultTableModel。
英文:
You would be better off using a JList or JTable which have built in selection functionality. Here is the Oracle documentation on the basics of JTable.
I suggest using JTable with the DefaultTableModel when you are first getting started.
答案2
得分: 0
你可以使用一个名为 process
的方法来打开文件或执行操作。
using System.Diagnostics;
Process p = new Process();
ProcessStartInfo pi = new ProcessStartInfo();
pi.UseShellExecute = true;
pi.FileName = @"MY_FILE_WITH_FULL_PATH.jpg"; //c:\Desktop\example\sample.txt
p.StartInfo = pi;
try
{
p.Start();
}
catch (Exception Ex)
{
//MessageBox.Show(Ex.Message);
}
英文:
Well you can open a file or execute using a method called process
using System.Diagnostics;
Process p = new Process();
ProcessStartInfo pi = new ProcessStartInfo();
pi.UseShellExecute = true;
pi.FileName = @"MY_FILE_WITH_FULL_PATH.jpg";//c:\Desktop\example\sample.txt
p.StartInfo = pi;
try
{
p.Start();
}
catch (Exception Ex)
{
//MessageBox.Show(Ex.Message);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论