In my small project, I am parsing some logfiles and showing on JTable. In Jtable there are 2 columns.
Second column is for => shows the searching sentence First column is for => shows where is the this sentence (in which log file ?)
There is a screenshot of my result screen.
Now, my problem is, I want to put JButtons on first column. But when I expect the show Jbutton I cant.
Here is the my code :
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.GridLayout;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
public class ResultGui
{
public final static boolean RIGHT_TO_LEFT = false;
private static JButton but;
private static JTable table;
public static void addComponentsToPane(Container contentPane,List<String> result, List<String> logFiles)
{
if (RIGHT_TO_LEFT)
{
contentPane.setComponentOrientation(
ComponentOrientation.RIGHT_TO_LEFT);
}
contentPane.setLayout(new GridLayout(0,1));
//list to array
String[] data = result.toArray(new String[result.size()]);
DefaultTableModel dm = new DefaultTableModel();
Object [][] objectArray = new Object[logFiles.size()][result.size()];
for(int i=0; i<logFiles.size(); i++)
{
but = new JButton("LogFile");
but.setToolTipText(logFiles.get(i));;
but.setOpaque(true);
objectArray [i][0] = but;
//objectArray [i][0] = logFiles.get(i);
i++;
objectArray [i][0] = "";
}
for(int i=0; i<result.size(); i++)
{
objectArray[i][1] = result.get(i);
}
dm.setDataVector(objectArray, new Object[] { "LOGFILES", "RESULTS" });
//dm.addColumn("deneme", strArray2Vector(data));
table = new JTable(dm);
TableColumn columnA = table.getColumn("LOGFILES");
columnA.setMinWidth(30);
columnA.setMaxWidth(100);
JScrollPane scrollPane = new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
contentPane.add(scrollPane);
}
public static void createAndShowGUI(List<String> stringList, List<String> logFiles)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Result Screen");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Set up the content pane and components in GridLayout
addComponentsToPane(frame.getContentPane(),stringList,logFiles);
frame.setSize(1000,500);
//frame.pack();
frame.setVisible(true);
}
}
What should I do for successfully create Jbutton in my table ? Any example, hint or advice is appreciated.