List of usage examples for javax.swing JTable JTable
public JTable()
JTable
that is initialized with a default data model, a default column model, and a default selection model. From source file:com.willwinder.universalgcodesender.uielements.panels.ControllerProcessorSettingsPanel.java
public ControllerProcessorSettingsPanel(Settings settings, IChanged changer, Map<String, ConfigTuple> configFiles) { super(settings, changer); this.configFiles = configFiles; this.controllerConfigs = new JComboBox(configFiles.keySet().toArray()); this.customRemoverTable = initCustomRemoverTable(new JTable()); super.updateComponents(); controllerConfigs.addActionListener(e -> { if (!updatingCombo) super.updateComponents(); });/* ww w . j a v a2 s . c o m*/ add.addActionListener(e -> this.addNewPatternRemover()); remove.addActionListener(e -> this.removeSelectedPatternRemover()); }
From source file:edu.harvard.mcz.imagecapture.UserListBrowser.java
/** * This method initializes jTable /*from w w w.j a v a 2s . co m*/ * * @return javax.swing.JTable */ private JTable getJTable() { if (jTable == null) { jTable = new JTable(); UsersTableModel model = new UsersTableModel(UsersLifeCycle.findAll()); jTable.setModel(model); jTable.setDefaultRenderer(Users.class, new ButtonRenderer()); jTable.setDefaultEditor(Users.class, new ButtonEditor(ButtonEditor.OPEN_USER, thisPanel)); } return jTable; }
From source file:org.streamspinner.harmonica.application.CQGraphTerminal.java
private JTable getJTable() { if (jTable == null) { jTable = new JTable(); String[] str = { " ", " ", " " }; DefaultTableModel tm = new DefaultTableModel(str, 0); jTable.setModel(tm);/*from w w w. j a v a2 s . c o m*/ } return jTable; }
From source file:gtu._work.etc.GoogleContactUI.java
private void initGUI() { try {//from w w w .j av a2 s . c o m BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("jPanel1", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); { DefaultTableModel model = JTableUtil.createModel(false, googleColumns); model.addRow(new Object[googleColumns.length]); googleTable = new JTable(); jScrollPane1.setViewportView(googleTable); googleTable.setModel(model); googleTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { JTableUtil.newInstance(googleTable).defaultToolTipText(evt); googleTableMouseClicked(evt); } }); JTableUtil.defaultSetting(googleTable); JTableUtil.newInstance(googleTable).showColumnByHeaderValue(defaultShow_googleColumns); } } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("jPanel2", null, jPanel2, null); } } pack(); this.setSize(642, 405); } catch (Exception e) { e.printStackTrace(); } }
From source file:gtu._work.ui.JSFMakerUI_attrDialog.java
private void initGUI() { try {// ww w.j a v a2 s.com final SwingActionUtil actionUtil = SwingActionUtil.newInstance(this); BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("attribute", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(379, 233)); { DefaultTableModel model = JTableUtil.createModel(true, "enable", "attribute", "value"); attrTable = new JTable(); //XXX defnine attribute model.addRow(transfromAttribute(new Attribute("size", null, "", new String[] { "", "3", "5", "10", "15", "20" }))); model.addRow(transfromAttribute( new Attribute("readonly", null, "", new String[] { "", "false", "true" }))); model.addRow(transfromAttribute( new Attribute("styleClass", null, "", new String[] { "", "readonly-input" }))); //XXX defnine attribute jScrollPane1.setViewportView(attrTable); attrTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); attrTable.setAutoscrolls(true); attrTable.setAutoCreateRowSorter(false); attrTable.setUpdateSelectionOnSort(false); attrTable.setAutoCreateColumnsFromModel(true); attrTable.setColumnSelectionAllowed(true); attrTable.setModel(model); attrTable.getTableHeader().setAutoscrolls(true); attrTable.getTableHeader().setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION); attrTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { actionUtil.invokeAction(evt); } }); attrTable.addKeyListener(JTableUtil.newInstance(attrTable).defaultKeyAdapter()); } } { confirmOk = new JButton(); jPanel1.add(confirmOk, BorderLayout.SOUTH); confirmOk.setText("OK"); confirmOk.setPreferredSize(new java.awt.Dimension(379, 32)); confirmOk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { actionUtil.invokeAction(evt); } }); } } actionUtil.addAction(confirmOk, ActionEvent.class, new Action() { public void action(EventObject evt) throws Exception { dispose(); setVisible(false); } }); actionUtil.addAction(attrTable, MouseEvent.class, new Action() { public void action(EventObject evt) throws Exception { if (!JMouseEventUtil.buttonLeftClick(2, evt)) { return; } int colPos = JTableUtil.newInstance(attrTable).getSelectedColumn(); int rowPos = JTableUtil.newInstance(attrTable).getSelectedRow(); Function func = Function.valueOf(colPos); if (func == null) { System.err.println("ERROR!!!!!"); return; } Attribute realAttr = (Attribute) JTableUtil.newInstance(attrTable).getModel() .getValueAt(rowPos, Function.VALUE.col); switch (func) { case ENABLE: boolean bool = (Boolean) JTableUtil.newInstance(attrTable).getModel().getValueAt(rowPos, Function.ENABLE.col); JTableUtil.newInstance(attrTable).getModel().setValueAt(!bool, rowPos, Function.ENABLE.col); break; case ATTRIBUTE: break; case VALUE: String value = (String) JOptionPaneUtil.newInstance().showInputDialog_drowdown("choice", "", realAttr.dropdown, realAttr.defaultVal); realAttr.value = value; JTableUtil.newInstance(attrTable).getModel().setValueAt(StringUtils.isNotEmpty(value), rowPos, Function.ENABLE.col); break; } } }); } setSize(400, 300); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.sf.profiler4j.console.ClassListPanel.java
/** * This method initializes classesTable//w ww. j av a2 s .co m * * @return javax.swing.JTable */ private JTable getClassesTable() { if (classesTable == null) { classesTable = new JTable(); classesTable.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); classesTable.setFont(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 12)); classesTable.setModel(getClassListTableModel()); classesTable.setRowHeight(20); classesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (classesTable.getSelectedRowCount() > 0) { addAsRuleButton.setEnabled(true); } else { addAsRuleButton.setEnabled(false); } } }); TableColumn c = classesTable.getColumnModel().getColumn(0); c.setMinWidth(50); c.setMaxWidth(50); c = classesTable.getColumnModel().getColumn(1); c.setMinWidth(300); c.setCellRenderer(new DefaultTableCellRenderer() { Font f1 = new Font("Tahoma", java.awt.Font.PLAIN, 12); Font f2 = new Font("Tahoma", java.awt.Font.BOLD, 12); @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (isSelected) { setFont(f2); } else { setFont(f1); } if (classListTableModel.getRow(row).info.isInstrumented()) { if (isSelected) { setForeground(Color.YELLOW); setBackground(Color.BLUE); } else { setBackground(Color.decode("#bbffbb")); setForeground(Color.BLACK); } } else { if (isSelected) { setForeground(Color.WHITE); setBackground(Color.BLUE); } else { setBackground(Color.WHITE); setForeground(Color.BLACK); } } setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 4)); return this; } }); } return classesTable; }
From source file:it.unibas.spicygui.vista.BestMappingsTopComponent.java
private void initComponent(Image imageNumber) { setName(NbBundle.getMessage(Costanti.class, Costanti.VIEW_BEST_MAPPINGS_TOP_COMPONENT)); setToolTipText(NbBundle.getMessage(Costanti.class, Costanti.VIEW_BEST_MAPPINGS_TOP_COMPONENT_TOOLTIP)); Image imageDefault = ImageUtilities.loadImage(Costanti.ICONA_VIEW_BEST_MAPPINGS, true); this.setIcon(ImageUtilities.mergeImages(imageDefault, imageNumber, Scenario.X_OFFSET_IMAGE_NUMBER, Scenario.Y_OFFSET_IMAGE_NUMBER)); messageLabel = new JTextArea(); messageLabel.setRows(2);// www . j a v a2s. c o m messageLabel.setEditable(false); messageLabel.setBackground(this.getBackground()); tabellaBestMappings = new JTable(); jScrollPane = new JScrollPane(); jScrollPane.setPreferredSize(new DimensionUIResource(150, this.getHeight())); this.setPreferredSize(new Dimension(150, this.getHeight())); this.setLayout(new BorderLayout()); this.add(messageLabel, BorderLayout.NORTH); this.add(jScrollPane, BorderLayout.CENTER); addSelectionListener(); }
From source file:it.unibas.spicygui.vista.RankedTransformationsTopComponent.java
private void initComponent() { messageLabel = new JTextArea(); messageLabel.setRows(2);//from w w w . j av a 2 s . c om messageLabel.setEditable(false); messageLabel.setBackground(this.getBackground()); tabellaRankedTransformations = new JTable(); jScrollPane = new JScrollPane(); jScrollPane.setPreferredSize(new DimensionUIResource(150, this.getHeight())); this.setPreferredSize(new Dimension(150, this.getHeight())); this.setLayout(new BorderLayout()); this.add(messageLabel, BorderLayout.NORTH); this.add(jScrollPane, BorderLayout.CENTER); addSelectionListener(); }
From source file:org.pgptool.gui.ui.keyslist.KeysTableView.java
private JScrollPane initTableComponent() { table = new JTable(); // Adjust some visual appearence table.setRowHeight(22);//from w w w .j ava2 s.c o m table.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); // Add listeners selectionModel = new DefaultListSelectionModel(); selectionModel.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION); selectionModel.addListSelectionListener(rowSelectionListener); table.setSelectionModel(selectionModel); table.addMouseListener(listMouseListener); initTableKeyListener(); // Envelope in scrollpane scrollPane = new JScrollPane(); scrollPane.addMouseListener(listMouseListener); scrollPane.setViewportView(table); return scrollPane; }
From source file:com.oracle.tutorial.jdbc.CoffeesFrame.java
public CoffeesFrame(JDBCTutorialUtilities settingsArg) throws SQLException { super("The Coffee Break: COFFEES Table"); // Set window title this.settings = settingsArg; connection = settings.getConnection(); // Close connections exit the application when the user // closes the window addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { try { connection.close();// w w w. j a va2 s . c o m } catch (SQLException sqle) { JDBCTutorialUtilities.printSQLException(sqle); } System.exit(0); } }); // Initialize and lay out window controls CachedRowSet myCachedRowSet = getContentsOfCoffeesTable(); myCoffeesTableModel = new CoffeesTableModel(myCachedRowSet); myCoffeesTableModel.addEventHandlersToRowSet(this); table = new JTable(); // Displays the table table.setModel(myCoffeesTableModel); label_COF_NAME = new JLabel(); label_SUP_ID = new JLabel(); label_PRICE = new JLabel(); label_SALES = new JLabel(); label_TOTAL = new JLabel(); textField_COF_NAME = new JTextField(10); textField_SUP_ID = new JTextField(10); textField_PRICE = new JTextField(10); textField_SALES = new JTextField(10); textField_TOTAL = new JTextField(10); button_ADD_ROW = new JButton(); button_UPDATE_DATABASE = new JButton(); button_DISCARD_CHANGES = new JButton(); label_COF_NAME.setText("Coffee Name:"); label_SUP_ID.setText("Supplier ID:"); label_PRICE.setText("Price:"); label_SALES.setText("Sales:"); label_TOTAL.setText("Total Sales:"); textField_COF_NAME.setText("Enter new coffee name"); textField_SUP_ID.setText("101"); textField_PRICE.setText("0"); textField_SALES.setText("0"); textField_TOTAL.setText("0"); button_ADD_ROW.setText("Add row to table"); button_UPDATE_DATABASE.setText("Update database"); button_DISCARD_CHANGES.setText("Discard changes"); // Place the components within the container contentPane; use GridBagLayout // as the layout. Container contentPane = getContentPane(); contentPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); contentPane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.CENTER; c.weightx = 0.5; c.weighty = 1.0; c.gridx = 0; c.gridy = 0; c.gridwidth = 2; contentPane.add(new JScrollPane(table), c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.25; c.weighty = 0; c.gridx = 0; c.gridy = 1; c.gridwidth = 1; contentPane.add(label_COF_NAME, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.75; c.weighty = 0; c.gridx = 1; c.gridy = 1; c.gridwidth = 1; contentPane.add(textField_COF_NAME, c); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.25; c.weighty = 0; c.anchor = GridBagConstraints.LINE_START; c.gridx = 0; c.gridy = 2; c.gridwidth = 1; contentPane.add(label_SUP_ID, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.75; c.weighty = 0; c.gridx = 1; c.gridy = 2; c.gridwidth = 1; contentPane.add(textField_SUP_ID, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.25; c.weighty = 0; c.gridx = 0; c.gridy = 3; c.gridwidth = 1; contentPane.add(label_PRICE, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.75; c.weighty = 0; c.gridx = 1; c.gridy = 3; c.gridwidth = 1; contentPane.add(textField_PRICE, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.25; c.weighty = 0; c.gridx = 0; c.gridy = 4; c.gridwidth = 1; contentPane.add(label_SALES, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.75; c.weighty = 0; c.gridx = 1; c.gridy = 4; c.gridwidth = 1; contentPane.add(textField_SALES, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.25; c.weighty = 0; c.gridx = 0; c.gridy = 5; c.gridwidth = 1; contentPane.add(label_TOTAL, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.75; c.weighty = 0; c.gridx = 1; c.gridy = 5; c.gridwidth = 1; contentPane.add(textField_TOTAL, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.5; c.weighty = 0; c.gridx = 0; c.gridy = 6; c.gridwidth = 1; contentPane.add(button_ADD_ROW, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.5; c.weighty = 0; c.gridx = 1; c.gridy = 6; c.gridwidth = 1; contentPane.add(button_UPDATE_DATABASE, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.5; c.weighty = 0; c.gridx = 0; c.gridy = 7; c.gridwidth = 1; contentPane.add(button_DISCARD_CHANGES, c); // Add listeners for the buttons in the application button_ADD_ROW.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(CoffeesFrame.this, new String[] { "Adding the following row:", "Coffee name: [" + textField_COF_NAME.getText() + "]", "Supplier ID: [" + textField_SUP_ID.getText() + "]", "Price: [" + textField_PRICE.getText() + "]", "Sales: [" + textField_SALES.getText() + "]", "Total: [" + textField_TOTAL.getText() + "]" }); try { myCoffeesTableModel.insertRow(textField_COF_NAME.getText(), Integer.parseInt(textField_SUP_ID.getText().trim()), Float.parseFloat(textField_PRICE.getText().trim()), Integer.parseInt(textField_SALES.getText().trim()), Integer.parseInt(textField_TOTAL.getText().trim())); } catch (SQLException sqle) { displaySQLExceptionDialog(sqle); } } }); button_UPDATE_DATABASE.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { myCoffeesTableModel.coffeesRowSet.acceptChanges(); } catch (SQLException sqle) { displaySQLExceptionDialog(sqle); // Now revert back changes try { createNewTableModel(); } catch (SQLException sqle2) { displaySQLExceptionDialog(sqle2); } } } }); button_DISCARD_CHANGES.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { createNewTableModel(); } catch (SQLException sqle) { displaySQLExceptionDialog(sqle); } } }); }