当前位置: 首页 > news >正文

网站开发必学的技巧有哪些杭州互联网网站定制公司

网站开发必学的技巧有哪些,杭州互联网网站定制公司,手机网站建设解决方案,织梦印刷公司网站源码以下示例显示如何获取选定的行或选定的列#xff0c;或如何选择JTable组件中的多个单元格。要侦听选择事件#xff0c;我们可以JTable通过调用JTable.getSelectionModel().addListSelectionListener()方法将选择侦听器添加到组件。该方法接受实现ListSelectionListener接口的…以下示例显示如何获取选定的行或选定的列或如何选择JTable组件中的多个单元格。要侦听选择事件我们可以JTable通过调用JTable.getSelectionModel().addListSelectionListener()方法将选择侦听器添加到组件。该方法接受实现ListSelectionListener接口的对象。package org.nhooo.example.swing;import javax.swing.*;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.table.AbstractTableModel;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Arrays;public class JTableGetSelectedCells extends JPanel {private JTable table  null;public JTableGetSelectedCells() {initializePanel();}private void initializePanel() {setLayout(new BorderLayout());setPreferredSize(new Dimension(500, 200));table  new JTable(new PremiereLeagueTableModel());table.getColumnModel().getColumn(0).setMinWidth(150);table.getSelectionModel().addListSelectionListener(new RowColumnListSelectionListener());table.setFillsViewportHeight(true);JScrollPane pane  new JScrollPane(table);JPanel control  new JPanel(new FlowLayout());final JCheckBox cb1  new JCheckBox(Row Selection);final JCheckBox cb2  new JCheckBox(Columns Selection);final JCheckBox cb3  new JCheckBox(Cells Selection);// 更改行选择允许状态cb1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {table.setRowSelectionAllowed(cb1.isSelected());table.setColumnSelectionAllowed(!cb1.isSelected());cb2.setSelected(!cb1.isSelected());}});// 更改列选择允许状态cb2.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {table.setColumnSelectionAllowed(cb2.isSelected());table.setRowSelectionAllowed(!cb2.isSelected());cb1.setSelected(!cb2.isSelected());}});// 启用单元格选择cb3.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {table.setCellSelectionEnabled(cb3.isSelected());table.setRowSelectionAllowed(cb3.isSelected());table.setColumnSelectionAllowed(cb3.isSelected());}});control.add(cb1);control.add(cb2);control.add(cb3);add(pane, BorderLayout.CENTER);add(control, BorderLayout.SOUTH);}private class RowColumnListSelectionListener implements ListSelectionListener {public void valueChanged(ListSelectionEvent e) {if (table.getRowSelectionAllowed() !table.getColumnSelectionAllowed()) {int[] rows  table.getSelectedRows();System.out.println(Selected Rows:   Arrays.toString(rows));}if (table.getColumnSelectionAllowed() !table.getRowSelectionAllowed()) {int[] cols  table.getSelectedColumns();System.out.println(Selected Columns:   Arrays.toString(cols));} else if (table.getCellSelectionEnabled()) {int selectionMode  table.getSelectionModel().getSelectionMode();System.out.println(selectionMode    selectionMode);if (selectionMode  ListSelectionModel.SINGLE_SELECTION) {int rowIndex  table.getSelectedRow();int colIndex  table.getSelectedColumn();System.out.printf(Selected [Row,Column]  [%d,%d]\n, rowIndex, colIndex);} else if (selectionMode  ListSelectionModel.SINGLE_INTERVAL_SELECTION ||selectionMode  ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) {int rowIndexStart  table.getSelectedRow();int rowIndexEnd  table.getSelectionModel().getMaxSelectionIndex();int colIndexStart  table.getSelectedColumn();int colIndexEnd  table.getColumnModel().getSelectionModel().getMaxSelectionIndex();for (int i  rowIndexStart; i  rowIndexEnd; i) {for (int j  colIndexStart; j  colIndexEnd; j) {if (table.isCellSelected(i, j)) {System.out.printf(Selected [Row,Column]  [%d,%d]\n, i, j);}}}}}}}private static void showFrame() {JPanel panel  new JTableGetSelectedCells();panel.setOpaque(true);JFrame frame  new JFrame(JTable Selected Cells Demo);frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);frame.setContentPane(panel);frame.pack();frame.setVisible(true);}public static void main(String[] args) {SwingUtilities.invokeLater(new Runnable() {public void run() {showFrame();}});}class PremiereLeagueTableModel extends AbstractTableModel {// TableModel的列名private String[] columnNames  {TEAM, P, W, D, L, GS, GA, GD, PTS};// TableModel的数据private Object[][] data  {{ Liverpool, 3, 3, 0, 0, 7, 0, 7, 9 },{ Tottenham, 3, 3, 0, 0, 8, 2, 6, 9 },{ Chelsea, 3, 3, 0, 0, 8, 3, 5, 9 },{ Watford, 3, 3, 0, 0, 7, 2, 5, 9 },{ Manchester City, 3, 2, 1, 0, 9, 2, 7, 7 }};public int getRowCount() {return data.length;}public int getColumnCount() {return columnNames.length;}Overridepublic String getColumnName(int column) {return columnNames[column];}public Object getValueAt(int rowIndex, int columnIndex) {return data[rowIndex][columnIndex];}}}运行程序时将显示以下屏幕。在中选择一些单元格JTable将以ListSelectionModel.MULTIPLE_INTERVAL_SELECTION选择模式打印选定的行选定的列或选定的行和列的某些索引。
http://www.yutouwan.com/news/362550/

相关文章:

  • 网站建设广告有哪些平台网络营销计划书范例
  • 0网站建设公司宣传册电子工程网官方网站
  • 站长之家ip查询锤子简历模板免费
  • 现在怎么做网站广宁住房和城乡建设局网站
  • 网站开发费用税企业集团网站建设方案
  • 做电子商务网站 语言上海办公室设计装修公司
  • 权重网站建设wordpress添加主题
  • 济宁网站开发软件开发需要用什么软件
  • 企业网站建设设计服务作一个网站要多少钱
  • 做信息发布网站要多少钱嘉兴网站建设需要多少钱
  • 企业网站官网建设cms网站建设教程
  • 网页设计网站建设的书籍顺电网上商城怎么样
  • 网站建设部网玉环建设规划局网站
  • 广东建设执业资格注册中心网站seo排名优化怎样
  • 成都网站排名提升网站开发了解客户需求
  • 网上做调查问卷的网站注册公司的网址是什么
  • 办个网站需要多少钱wordpress商品管理
  • 网站建设评估报告怎样搭建微网站
  • 衡阳网站建设公司地址简单的微信小程序项目
  • 网站LOGO透明底色PNG格式怎么做的做园林景观的网站
  • 开发什么网站媒体公关公司
  • 西安做网站陕西必达网站哪个公司做的比较好
  • 对于网站链接优化有哪些建议公司网站实名认证
  • 池州网站开发枣庄手机网站建设公司
  • 上海好的网站有哪些网站建设类岗位有哪些
  • 电子商务做网站设计北京网站设计公司wyhseo
  • 网站网页设计怎么报价开展建设文明网站活动方案
  • 网站建设实验分析怎么做百度网站验证码
  • 做微网站的第三方登录界面东莞网站设计方案
  • 游戏加盟招商手机网站关键词优化