List of usage examples for javax.swing JTable setAutoCreateRowSorter
@BeanProperty(preferred = true, description = "Whether or not to turn on sorting by default.") public void setAutoCreateRowSorter(boolean autoCreateRowSorter)
From source file:Main.java
public Main() { TableModel dataModel = new MyTableModel(); JTable table = new JTable(dataModel); table.setAutoCreateRowSorter(true); table.getColumnModel().getColumn(0).setPreferredWidth(100); table.getColumnModel().getColumn(1).setPreferredWidth(150); table.getColumnModel().getColumn(2).setPreferredWidth(200); JScrollPane jsp = new JScrollPane(table); this.add(jsp); }
From source file:gui.accessories.BattleSimFx.java
@Override public void init() { tableModel = new SampleTableModel(); // create javafx panel for charts chartFxPanel = new JFXPanel(); chartFxPanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, PANEL_HEIGHT_INT)); //JTable// w w w.j av a2 s. co m JTable table = new JTable(tableModel); table.setAutoCreateRowSorter(true); table.setGridColor(Color.DARK_GRAY); BattleSimFx.DecimalFormatRenderer renderer = new BattleSimFx.DecimalFormatRenderer(); renderer.setHorizontalAlignment(JLabel.RIGHT); for (int i = 0; i < table.getColumnCount(); i++) { table.getColumnModel().getColumn(i).setCellRenderer(renderer); } JScrollPane tablePanel = new JScrollPane(table); tablePanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, TABLE_PANEL_HEIGHT_INT)); JPanel chartTablePanel = new JPanel(); chartTablePanel.setLayout(new BorderLayout()); //Split pane that holds both chart and table JSplitPane jsplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); jsplitPane.setTopComponent(chartTablePanel); jsplitPane.setBottomComponent(tablePanel); jsplitPane.setDividerLocation(410); chartTablePanel.add(chartFxPanel, BorderLayout.CENTER); // add(tablePanel, BorderLayout.CENTER); add(jsplitPane, BorderLayout.CENTER); // create JavaFX scene Platform.runLater(new Runnable() { @Override public void run() { createScene(); } }); }
From source file:SampleTableModel.java
@Override public void init() { tableModel = new SampleTableModel(); // create javafx panel for charts chartFxPanel = new JFXPanel(); chartFxPanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, PANEL_HEIGHT_INT)); //JTable//ww w .j a v a 2 s .c o m JTable table = new JTable(tableModel); table.setAutoCreateRowSorter(true); table.setGridColor(Color.DARK_GRAY); SwingInterop.DecimalFormatRenderer renderer = new SwingInterop.DecimalFormatRenderer(); renderer.setHorizontalAlignment(JLabel.RIGHT); for (int i = 0; i < table.getColumnCount(); i++) { table.getColumnModel().getColumn(i).setCellRenderer(renderer); } JScrollPane tablePanel = new JScrollPane(table); tablePanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, TABLE_PANEL_HEIGHT_INT)); JPanel chartTablePanel = new JPanel(); chartTablePanel.setLayout(new BorderLayout()); //Split pane that holds both chart and table JSplitPane jsplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); jsplitPane.setTopComponent(chartTablePanel); jsplitPane.setBottomComponent(tablePanel); jsplitPane.setDividerLocation(410); chartTablePanel.add(chartFxPanel, BorderLayout.CENTER); // add(tablePanel, BorderLayout.CENTER); add(jsplitPane, BorderLayout.CENTER); // create JavaFX scene Platform.runLater(new Runnable() { @Override public void run() { createScene(); } }); }
From source file:components.TableSortDemo.java
public TableSortDemo() { super(new GridLayout(1, 0)); JTable table = new JTable(new MyTableModel()); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true);/* w w w. ja v a 2 s.c o m*/ table.setAutoCreateRowSorter(true); //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this panel. add(scrollPane); }
From source file:view.ResultsPanel.java
public void showHistogram(List<ElementaryMode> modes) { //for the JTable DefaultTableModel tableModel = new DefaultTableModel(); JTable tableResult = new JTable(); tableResult.setModel(tableModel);//from w w w. jav a 2s .c o m tableModel.addColumn("Reaction"); tableModel.addColumn("Presence in the modes"); tableResult.setAutoCreateRowSorter(true); Map<Reaction, Double> stats = new HashMap<Reaction, Double>(); DecimalFormat df = new DecimalFormat("0.00"); for (ElementaryMode em : modes) { for (Reaction r : em.getContent().keySet()) { if (em.getContent().containsKey(r)) { if (!stats.containsKey(r)) { stats.put(r, 1.0); } else { Reaction key = r; Double value = stats.get(r) + 1; stats.remove(key); stats.put(key, value); } } } } for (Reaction r : stats.keySet()) { tableModel .addRow(new Object[] { r, String.valueOf(df.format(stats.get(r) * 100 / modes.size())) + "%" }); } JFrame statisticFrame = new JFrame(); statisticFrame.add(new JScrollPane(tableResult), BorderLayout.CENTER); statisticFrame.setVisible(true); statisticFrame.setSize(400, 350); statisticFrame.setTitle("Representativeness of each reaction"); statisticFrame.setLocation(500, 600); //histogram DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Map<Integer, Integer> data = new TreeMap<Integer, Integer>(); int maxSize = 0; for (ElementaryMode em : modes) { int modeLength = em.getContent().size(); if (modeLength > maxSize) { maxSize = modeLength; } if (data.containsKey(modeLength)) { int value = data.get(modeLength) + 1; data.put(modeLength, value); } else { data.put(modeLength, 1); } } for (int i = 1; i < maxSize; i++) { if (!data.containsKey(i)) { data.put(i, 0); } } for (int key : data.keySet()) { dataset.addValue(Integer.valueOf((data.get(key))), "test", Integer.valueOf(key)); } String plotTitle = "Number of reactions per elementary mode"; String xaxis = "Reaction number"; String yaxis = "Elementary mode number"; PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = false; boolean toolTips = false; boolean urls = false; JFreeChart chart = ChartFactory.createBarChart3D(plotTitle, xaxis, yaxis, dataset, orientation, show, toolTips, urls); CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis axis = plot.getDomainAxis(); plot.getDomainAxis(0).setLabelFont(plot.getDomainAxis().getLabelFont().deriveFont(new Float(11))); ChartFrame frame = new ChartFrame("Elementary modes", chart); frame.setVisible(true); frame.setSize(400, 350); frame.setLocation(500, 100); }
From source file:de.wusel.partyplayer.gui.PartyPlayer.java
private Component createSongPanel() { final SongsTableModel model = new SongsTableModel(playerModel, settings, this); table = new JXTable(model) { @Override// w ww. j ava 2s .co m public String getToolTipText(MouseEvent event) { int viewRowIndex = rowAtPoint(event.getPoint()); if (viewRowIndex != -1) { int modelIndex = convertRowIndexToModel(viewRowIndex); SongWrapper songFromList = playerModel.getSongFromList(modelIndex); return songFromList.getFileName(); } return super.getToolTipText(event); } }; table.setAutoCreateRowSorter(true); String numberColumnName = getText("table.songs.column.number.label"); table.getColumn(numberColumnName).setMaxWidth(25); table.getColumn(numberColumnName).setResizable(false); TableSortController sorter = (TableSortController) table.getRowSorter(); sorter.setComparator(2, new SongComparator()); table.getColumn(numberColumnName).setCellRenderer(new SubstanceDefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value != null) label.setText(((SongWrapper) value).getTrackNumber() + ""); return label; } }); table.getColumn(getText("table.songs.column.duration.label")) .setCellRenderer(new SubstanceDefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value != null) label.setText(Util.getTimeString((Double) value)); return label; } }); table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { addSongToPlaylist( playerModel.getSongFromList(table.convertRowIndexToModel(table.getSelectedRow()))); } } }); table.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { addSongToPlaylist( playerModel.getSongFromList(table.convertRowIndexToModel(table.getSelectedRow()))); } } }); JScrollPane scrollPane = new JScrollPane(table); table.setFillsViewportHeight(true); return scrollPane; }
From source file:coolmap.application.widget.impl.WidgetUserGroup.java
private void init() { table.getTableHeader().setReorderingAllowed(false); table.setAutoCreateRowSorter(true); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { @Override/*from www .ja v a2s. c o m*/ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (isSelected) { return label; } if (column == 1) { try { label.setBackground( nodeColor.get(table.getModel().getValueAt(table.convertRowIndexToModel(row), 0))); } catch (Exception e) { } } else { label.setBackground(UI.colorWhite); } return label; } }); //Need a search box as well. // getContentPane().setLayout(new BorderLayout()); // getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); JToolBar t = new JToolBar(); getContentPane().add(t, BorderLayout.NORTH); t.setFloatable(false); try { //also add an action to add group nodes JMenuItem item = new JMenuItem("selected row nodes"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { CoolMapObject o = CoolMapMaster.getActiveCoolMapObject(); if (o == null) { return; } ArrayList<Range<Integer>> selected = o.getCoolMapView().getSelectedRows(); ArrayList<VNode> selectedNodes = new ArrayList<>(); for (Range<Integer> r : selected) { for (int i = r.lowerEndpoint(); i < r.upperEndpoint(); i++) { selectedNodes.add(o.getViewNodeRow(i)); } } createNewGroup(selectedNodes); //create a group } }); WidgetMaster.getViewport().addPopupMenuItem("Create group", item, false); item = new JMenuItem("selected column nodes"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { CoolMapObject o = CoolMapMaster.getActiveCoolMapObject(); if (o == null) { return; } ArrayList<Range<Integer>> selected = o.getCoolMapView().getSelectedColumns(); ArrayList<VNode> selectedNodes = new ArrayList<>(); for (Range<Integer> r : selected) { for (int i = r.lowerEndpoint(); i < r.upperEndpoint(); i++) { selectedNodes.add(o.getViewNodeColumn(i)); } } createNewGroup(selectedNodes); } }); WidgetMaster.getViewport().addPopupMenuItem("Create group", item, false); } catch (Exception e) { // //Error handling. } }
From source file:fll.subjective.SubjectiveFrame.java
private void createSubjectiveTable(final JTabbedPane tabbedPane, final ScoreCategory subjectiveCategory) { final SubjectiveTableModel tableModel = new SubjectiveTableModel(_scoreDocument, subjectiveCategory, _schedule, _scheduleColumnMappings); final JTable table = new JTable(tableModel); table.setDefaultRenderer(Date.class, DateRenderer.INSTANCE); // Make grid lines black (needed for Mac) table.setGridColor(Color.BLACK); // auto table sorter table.setAutoCreateRowSorter(true); final String title = subjectiveCategory.getTitle(); _tables.put(title, table);//www.ja v a2s. c o m final JScrollPane tableScroller = new JScrollPane(table); tableScroller.setPreferredSize(new Dimension(640, 480)); tabbedPane.addTab(title, tableScroller); table.setSelectionBackground(Color.YELLOW); setupTabReturnBehavior(table); int goalIndex = 0; for (final AbstractGoal goal : subjectiveCategory.getGoals()) { final TableColumn column = table.getColumnModel() .getColumn(goalIndex + tableModel.getNumColumnsLeftOfScores()); if (goal.isEnumerated()) { final Vector<String> posValues = new Vector<String>(); posValues.add(""); for (final EnumeratedValue posValue : goal.getSortedValues()) { posValues.add(posValue.getTitle()); } column.setCellEditor(new DefaultCellEditor(new JComboBox<String>(posValues))); } else { final JTextField editor = new SelectTextField(); column.setCellEditor(new DefaultCellEditor(editor)); } ++goalIndex; } }
From source file:net.sf.maltcms.chromaui.msviewer.ui.panel.MassSpectrumPanel.java
public void addIdentification() { // Create a custom NotifyDescriptor, specify the panel instance as a parameter + other params NotifyDescriptor nd = new NotifyDescriptor(ddp, // instance of your panel "Select Databases and Settings", // title of the dialog NotifyDescriptor.OK_CANCEL_OPTION, // it is Yes/No dialog ... NotifyDescriptor.PLAIN_MESSAGE, // ... of a question type => a question mark icon null, // we have specified YES_NO_OPTION => can be null, options specified by L&F, // otherwise specify options as: // new Object[] { NotifyDescriptor.YES_OPTION, ... etc. }, NotifyDescriptor.OK_OPTION // default option is "Yes" );/* w ww . j av a 2 s . c o m*/ ddp.updateView(); // let's display the dialog now... if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.OK_OPTION) { if (ddp.getSelectedDatabases().isEmpty()) { return; } Runnable r = new Runnable() { @Override public void run() { IQuery<IScan> query = Lookup.getDefault().lookup(IQueryFactory.class).createQuery( ddp.getSelectedDatabases(), ddp.getRetentionIndexCalculator(), ddp.getSelectedMetabolitePredicate(), ddp.getMatchThreshold(), ddp.getMaxNumberOfHits(), ddp.getRIWindow(), seriesToScan.values().toArray(new IScan[seriesToScan.size()])); try { List<QueryResultList<IScan>> results = query.call(); Box outerBox = Box.createVerticalBox(); for (QueryResultList<IScan> mdqrl : results) { for (IQueryResult<IScan> result : mdqrl) { Box vbox = Box.createVerticalBox(); JLabel label = new JLabel("Results for scan " + result.getScan().getScanIndex() + " at " + result.getScan().getScanAcquisitionTime() + " with ri: " + result.getRetentionIndex()); JLabel dbLabel = new JLabel( "DB: " + result.getDatabaseDescriptor().getResourceLocation()); vbox.add(label); vbox.add(dbLabel); JLabel parameterLabel = new JLabel("Minimum Score: " + ddp.getMatchThreshold() + "; Maximum #Hits Returned: " + ddp.getMaxNumberOfHits()); vbox.add(parameterLabel); DefaultTableModel dlm = new DefaultTableModel( new String[] { "Score", "RI", "Name", "ID", "MW", "Formula", "Max Mass" }, 0); for (IMetabolite metabolite : result.getMetabolites()) { String name = metabolite.getName(); if (name.lastIndexOf("_") != -1) { name = name.substring(name.lastIndexOf("_") + 1); } dlm.addRow(new Object[] { result.getScoreFor(metabolite), result.getRiFor(metabolite), name, metabolite.getID(), metabolite.getMW(), metabolite.getFormula(), metabolite.getMaxMass() }); } JTable jl = new JTable(dlm); JScrollPane resultScrollPane = new JScrollPane(jl); jl.setAutoCreateRowSorter(true); jl.setUpdateSelectionOnSort(true); vbox.add(resultScrollPane); outerBox.add(vbox); outerBox.add(Box.createVerticalStrut(10)); } } JScrollPane jsp = new JScrollPane(outerBox); NotifyDescriptor nd = new NotifyDescriptor(jsp, // instance of your panel "Database Search Results", // title of the dialog NotifyDescriptor.OK_CANCEL_OPTION, // it is Yes/No dialog ... NotifyDescriptor.PLAIN_MESSAGE, // ... of a question type => a question mark icon null, // we have specified YES_NO_OPTION => can be null, options specified by L&F, // otherwise specify options as: // new Object[] { NotifyDescriptor.YES_OPTION, ... etc. }, NotifyDescriptor.OK_OPTION // default option is "Yes" ); if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.OK_OPTION) { } //DBConnectionManager.close(); } catch (Exception ex) { Exceptions.printStackTrace(ex); } } }; RequestProcessor.getDefault().post(r); } }
From source file:fi.hoski.remote.ui.Admin.java
private void editReservations(final EventType eventType) { final Event event = chooseEvent(eventType, "CHOOSE"); if (event != null) { final String eventTitle = TextUtil.getText(event.getEventType().name()) + " " + event.get(Event.EventDate); safeTitle = frame.getTitle();// w w w.jav a 2 s. com frame.setTitle(eventTitle); reservationList = dss.getReservations(event); selectedReservations = new ArrayList<Reservation>(); unSelectedReservations = new ArrayList<Reservation>(); if (Event.isInspection(eventType)) { for (Reservation reservation : reservationList) { Boolean inspected = (Boolean) reservation.get(Reservation.INSPECTED); if (inspected != null && inspected) { selectedReservations.add(reservation); } else { unSelectedReservations.add(reservation); } } } else { for (Reservation reservation : reservationList) { Long order = (Long) reservation.get(Reservation.ORDER); if (order != null && order != 0) { selectedReservations.add(reservation); } else { unSelectedReservations.add(reservation); } } } DataObjectModel baseModel = Reservation.getModel(eventType); DataObjectModel unorderedModel = null; DataObjectModel orderedModel = null; switch (eventType) { case LAUNCH: case LIFT: case HULL_INSPECTION: unorderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR); orderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR); break; case INSPECTION: unorderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR, Reservation.EMAIL, Reservation.MOBILEPHONE, Reservation.DOCK, Reservation.DOCKNUMBER, Reservation.INSPECTION_GASS, Reservation.INSPECTOR); orderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR, Reservation.EMAIL, Reservation.MOBILEPHONE, Reservation.DOCK, Reservation.DOCKNUMBER, Reservation.NOTES); break; } final DataObjectListTableModel<Reservation> unorderedTableModel = new DataObjectListTableModel<Reservation>( unorderedModel, unSelectedReservations); final JTable unorderedtable = new FitTable(unorderedTableModel); TableSelectionHandler tsh1 = new TableSelectionHandler(unorderedtable); unorderedtable.setDefaultRenderer(String.class, new StringTableCellRenderer()); unorderedtable.setDefaultRenderer(Text.class, new TextTableCellRenderer()); unorderedtable.addKeyListener(unorderedTableModel.getRemover(dss)); unorderedtable.setDragEnabled(true); unorderedtable.setDropMode(DropMode.INSERT_ROWS); TransferHandler unorderedTransferHandler = new DataObjectTransferHandler<Reservation>( unorderedTableModel); unorderedtable.setTransferHandler(unorderedTransferHandler); final DataObjectListTableModel<Reservation> orderedTableModel = new DataObjectListTableModel<Reservation>( orderedModel, selectedReservations); orderedTableModel.setEditable(Reservation.INSPECTION_CLASS, Reservation.INSPECTION_GASS, Reservation.BASICINSPECTION, Reservation.INSPECTOR); final JTable orderedtable = new FitTable(orderedTableModel); TableSelectionHandler tsh2 = new TableSelectionHandler(orderedtable); orderedtable.setDefaultRenderer(String.class, new StringTableCellRenderer()); orderedtable.setDefaultRenderer(Text.class, new TextTableCellRenderer()); orderedtable.addKeyListener(orderedTableModel.getRemover(dss)); orderedtable.setDragEnabled(true); orderedtable.setDropMode(DropMode.INSERT_ROWS); TransferHandler orderedTransferHandler = new DataObjectTransferHandler<Reservation>(orderedTableModel); orderedtable.setTransferHandler(orderedTransferHandler); if (Event.isInspection(eventType)) { unorderedtable.setAutoCreateRowSorter(true); orderedtable.setAutoCreateRowSorter(true); } leftPane = new JScrollPane(); leftPane.setViewport(new InfoViewport(TextUtil.getText(eventType.name() + "-leftPane"))); leftPane.setViewportView(unorderedtable); leftPane.setTransferHandler(unorderedTransferHandler); rightPane = new JScrollPane(); rightPane.setViewport(new InfoViewport(TextUtil.getText(eventType.name() + "-rightPane"))); rightPane.setViewportView(orderedtable); rightPane.setTransferHandler(orderedTransferHandler); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPane, rightPane); splitPane.setDividerLocation(0.5); menuReservation.setEnabled(false); safeContainer = frame.getContentPane(); JPanel contentPane = new JPanel(new BorderLayout()); contentPane.add(splitPane, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout()); contentPane.add(buttonPanel, BorderLayout.SOUTH); JButton saveButton = new JButton(); TextUtil.populate(saveButton, "SAVE"); saveButton.setEnabled(!Event.isInspection(eventType)); ActionListener saveAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveReservations(); } }; saveButton.addActionListener(saveAction); buttonPanel.add(saveButton); switch (eventType) { case INSPECTION: { if (privileged) { JButton inspectButton = new JButton(); TextUtil.populate(inspectButton, "SET INSPECTED"); ActionListener inspectAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { TableCellEditor cellEditor = orderedtable.getCellEditor(); if (cellEditor != null) { cellEditor.stopCellEditing(); } try { setAsInspected(); } catch (SQLException | ClassNotFoundException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, ex.getMessage()); } } }; inspectButton.addActionListener(inspectAction); buttonPanel.add(inspectButton); } JButton addBoat = new JButton(); TextUtil.populate(addBoat, "ADD BOAT"); ActionListener addBoatAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Reservation reservation = reservate(eventType, event); if (reservation != null) { reservationList.add(reservation); unSelectedReservations.add(reservation); unorderedTableModel.fireTableDataChanged(); } } }; addBoat.addActionListener(addBoatAction); buttonPanel.add(addBoat); JButton printTypeButton = new JButton(); TextUtil.populate(printTypeButton, "PRINT"); ActionListener printTypeAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { printNameBoatTypeOrder(eventTitle); } catch (PrinterException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, ex.getMessage()); } } }; printTypeButton.addActionListener(printTypeAction); buttonPanel.add(printTypeButton); JButton printDockButton = new JButton(); TextUtil.populate(printDockButton, "PRINT DOCK ORDER"); ActionListener printDockAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { printDockOrder(eventTitle); } catch (PrinterException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, ex.getMessage()); } } }; printDockButton.addActionListener(printDockAction); buttonPanel.add(printDockButton); } break; case HULL_INSPECTION: { JButton print = new JButton(); TextUtil.populate(print, "PRINT"); ActionListener printAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { printAlphaOrder(eventTitle); } catch (PrinterException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, ex.getMessage()); } } }; print.addActionListener(printAction); buttonPanel.add(print); } break; case LAUNCH: case LIFT: { JButton addBoat = new JButton(); TextUtil.populate(addBoat, "ADD BOAT"); ActionListener addBoatAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Reservation reservation = reservate(eventType, event); if (reservation != null) { reservationList.add(reservation); unSelectedReservations.add(reservation); unorderedTableModel.fireTableDataChanged(); } } }; addBoat.addActionListener(addBoatAction); buttonPanel.add(addBoat); JButton printBrief = new JButton(); TextUtil.populate(printBrief, "BRIEF PRINT"); ActionListener printBriefAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { printOrderBrief(eventTitle); } catch (PrinterException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, ex.getMessage()); } } }; printBrief.addActionListener(printBriefAction); buttonPanel.add(printBrief); JButton print = new JButton(); TextUtil.populate(print, "PRINT"); ActionListener printAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { if (eventType == EventType.LAUNCH) { printLaunchOrder(eventTitle); } else { printLiftOrder(eventTitle); } } catch (PrinterException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, ex.getMessage()); } } }; print.addActionListener(printAction); buttonPanel.add(print); } break; } JButton cancelButton = new JButton(); TextUtil.populate(cancelButton, "CANCEL"); ActionListener cancelAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cancel(); } }; cancelButton.addActionListener(cancelAction); buttonPanel.add(cancelButton); frame.setContentPane(contentPane); frame.pack(); frame.setVisible(true); KeyListener keyListener = new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == 10) { int selectedRow = unorderedtable.getSelectedRow(); if (selectedRow != -1) { RowSorter<? extends TableModel> rowSorter = unorderedtable.getRowSorter(); if (rowSorter != null) { selectedRow = rowSorter.convertRowIndexToModel(selectedRow); } Reservation reservation = unorderedTableModel.getObject(selectedRow); orderedTableModel.add(reservation); unorderedTableModel.remove(reservation); e.consume(); unorderedtable.changeSelection(selectedRow, 0, false, false); } } } }; unorderedtable.addKeyListener(keyListener); unorderedtable.requestFocusInWindow(); } }