ループ内にない関数で使用するために、for ループ内から見つけた値を取得する必要がありますが、これを行う方法がわかりません。私が達成したいと思っているのは、ハッシュマップのキーから値を抽出して、JTable
その行が選択されている場合にのみプロットすることです(を使用ListSelectionListener
)。このようにして、多くの時間を節約できる 100 個のテーブルをグラフ化することを避けることができます。また、私は使用してDefaultTableModel
います。
これは私の for ループです:
tableMaker(model);
for(Map.Entry<String,NumberHolder> entry : entries)
{
//add rows for each entry of the hashmap to the table
double[] v = new double[entry.getValue().singleValues.size()];
int i = 0;
for(Long j : entry.getValue().singleValues)
{
v[i++] = j.doubleValue();
}
//right here I need to take "v"
//and use it in my tableMaker function for that specific row
}
私のtableMaker
関数では、 my を作成して a をJTable
追加ListSelectionListener
します。行が選択されたときにヒストグラムを作成し、lowerPanel に追加したいと考えています。これはコードの一部です。v
データセットを作成できるようにする必要があります。
public static void tableMaker(DefaultTableModel m)
{
JPanel lowerPanel = new JPanel();
//create table here
frame.getContentPane().add(lowerPanel, BorderLayout.SOUTH);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
JFreeChart chart = ChartFactory.createHistogram(
plotTitle, xaxis, yaxis, dataset, orientation,
show, toolTips, urls);
// lowerPanel.add(chart);
// lowerPanel.revalidate();
}
}
});
}