通过将参数作为组件名称返回JTable的函数 [英] Function returning the JTable by taking parameter as a Component's Name
本文介绍了通过将参数作为组件名称返回JTable的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public JTable getTable(String Component_name)
{
JTable table=new JTable();
//in this function i want to search all the JTables that have been created on runtime!
//and then i want to return one JTable by the name "Component_Name"//
return table;
}
这就是我希望我的功能能够做到的;我想出了一种创建具有私有JTable表和私有String名称的Components新类的解决方案,但是按名称搜索JTables仍然存在问题.
This is how i want my function to be ; i came up with a solution of creating a new class of Components having private JTable table and private String name, But still problem comes up at searching JTables by name.
推荐答案
成功回答!
我创建了 私有ArrayList List = new ArrayList();
I created private ArrayList List=new ArrayList();
并在我的ActionListener中::
and in my ActionListener::
AddTableMenuItem.addActionListener(new ActionListener()
{
//This method will be called whenever you click the button.
public void actionPerformed(ActionEvent e){
Table table=new Table();
JTable.setName("Table"+count);
AddT(table); // Table List
}
其中
public ArrayList<JTable> getTable()
{
return List;
}
public void AddT(JTable tl)
{
if(tl.getName()!=null)
{getTable().add(tl);}
else return;
}
现在我有一个所有JTable的列表,现在我可以按名称实现来获取它们了,如下所示:
Now i have a List of all JTables that now i can fetch by names implementation as follows::
JTable one= new JTable();
JTable two= new JTable();
ComboBoxModel combo = comboBox.getModel();
for(JPanel t: getTable())
{
if(combo.getSelectedItem().equals(t.getName()))
{
one=t;
}
}
这篇关于通过将参数作为组件名称返回JTable的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文