您好我想选择一行,点击按钮后我想显示这一行!
public class TableDemo extends JPanel {
static List<String[]> rosterList = new ArrayList<String[]>();
int[] rowIndices;
public TableDemo() {
super(new BorderLayout(3, 3));
final JTable table = new JTable(new MyTableModel());
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
final JButton button = new JButton("Buy it");
JPanel buttonCenter = new JPanel(new FlowLayout(FlowLayout.CENTER));
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (table.getColumnSelectionAllowed()
&& !table.getRowSelectionAllowed()) {
// Column selection is enabled
// Get the indices of the selected columns
int[] …Run Code Online (Sandbox Code Playgroud) 嗨,我想把我的按钮放在南方位置!我怎样才能做到这一点?这是我的代码:
import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.io.*;
import java.util.*;
import javax.swing.JButton;
public class TableDemo extends JPanel {
private static Icon leftButtonIcon;
private boolean DEBUG = false;
// added static infront becuase got non static referencing error
static List<String[]> rosterList = new ArrayList<String[]>();
public TableDemo() {
super(new GridLayout(1,0));
JTable table = new JTable(new MyTableModel());
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
JButton button=new JButton("Buy it");
button.setSize(30,60);
button.add(button);
//Create the scroll pane and …Run Code Online (Sandbox Code Playgroud)