List of usage examples for javax.swing.table TableColumn setPreferredWidth
@BeanProperty(description = "The preferred width of the column.") public void setPreferredWidth(int preferredWidth)
preferredWidth
. From source file:ome.formats.importer.gui.ErrorTable.java
/** * Constructor for class/*from ww w . j av a2 s . c o m*/ */ public ErrorTable() { // set to layout that will maximize on resizing setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); this.setOpaque(false); // Main Panel containing all elements // Set up the main panel layout double mainTable[][] = { { 5, 200, 140, TableLayout.FILL, 140, 5 }, // columns { 5, TableLayout.PREFERRED, TableLayout.FILL, 5, 29, 5 } }; // rows mainPanel = GuiCommonElements.addMainPanel(this, mainTable, 0, 0, 0, 0, debug); String message = "All errors accumulated during your import are displayed here, " + "and will be uploaded to us if check-marked. You can send us feedback on " + "these problems by clicking the 'Send Feedback' button."; JTextPane instructions = GuiCommonElements.addTextPane(mainPanel, message, "1,1,4,0", debug); instructions.setMargin(new Insets(10, 10, 10, 10)); TableColumnModel cModel = eTable.getColumnModel(); // *** remove last 3 rows from display *** TableColumn hiddenColumn = cModel.getColumn(6); cModel.removeColumn(hiddenColumn); hiddenColumn = cModel.getColumn(5); cModel.removeColumn(hiddenColumn); hiddenColumn = cModel.getColumn(4); cModel.removeColumn(hiddenColumn); MyTableHeaderRenderer myHeader = new MyTableHeaderRenderer(); //LeftTableHeaderRenderer leftHeader = new LeftTableHeaderRenderer(); // Create a custom header for the table cModel.getColumn(0).setHeaderRenderer(myHeader); cModel.getColumn(1).setHeaderRenderer(myHeader); cModel.getColumn(2).setHeaderRenderer(myHeader); cModel.getColumn(3).setHeaderRenderer(myHeader); cbe = new CheckboxCellEditor(new JCheckBox()); cbe.checkbox.addMouseListener(this); cbr = new CheckboxRenderer(); cModel.getColumn(0).setCellEditor(cbe); cModel.getColumn(0).setCellRenderer(cbr); cModel.getColumn(1).setCellRenderer(new LeftDotRenderer()); cModel.getColumn(2).setCellRenderer(new TextLeftRenderer()); cModel.getColumn(3).setCellRenderer(new StatusRenderer()); // Set the width of the status column TableColumn statusColumn = eTable.getColumnModel().getColumn(3); statusColumn.setPreferredWidth(statusWidth); statusColumn.setMaxWidth(statusWidth); statusColumn.setMinWidth(statusWidth); // Set the width of the error column TableColumn dateColumn = eTable.getColumnModel().getColumn(2); dateColumn.setPreferredWidth(errorWidth); dateColumn.setMaxWidth(errorWidth); dateColumn.setMinWidth(errorWidth); // Set the width of the upload column TableColumn uploadColumn = eTable.getColumnModel().getColumn(0); uploadColumn.setPreferredWidth(uploadWidth); uploadColumn.setMaxWidth(uploadWidth); uploadColumn.setMinWidth(uploadWidth); eTable.setRowSelectionAllowed(false); // Add the table to the scollpane JScrollPane scrollPane = new JScrollPane(eTable); mainPanel.add(scrollPane, "1,2,4,1"); double progressTable[][] = { { 200 }, // columns { 12, 5, 12 } }; // rows progressPanel = GuiCommonElements.addPlanePanel(mainPanel, progressTable, debug); runThread = new Thread() { public void run() { try { bytesProgressBar = new JProgressBar(); progressPanel.add(bytesProgressBar, "0,0"); filesProgressBar = new JProgressBar(0, 20); progressPanel.add(filesProgressBar, "0,2"); } catch (Throwable error) { } } }; runThread.start(); mainPanel.add(progressPanel, "1,4"); progressPanel.setVisible(false); cancelBtn = GuiCommonElements.addButton(mainPanel, "Cancel", 'c', "Cancel sending", "2,4,L,C", debug); cancelBtn.addActionListener(this); cancelBtn.setVisible(false); clearDoneBtn = GuiCommonElements.addButton(mainPanel, "Clear Done", 'd', "Clear done", "3,4,R,C", debug); clearDoneBtn.addActionListener(this); clearDoneBtn.setOpaque(false); clearDoneBtn.setEnabled(false); //clearDoneBtn.setVisible(false); // Disabled (See #5250) sendBtn = GuiCommonElements.addButton(mainPanel, "Send Feedback", 's', "Send your errors to the OMERO team", "4,4,R,C", debug); sendBtn.setOpaque(false); sendBtn.addActionListener(this); sendBtn.setEnabled(false); this.add(mainPanel); }
From source file:ome.formats.importer.gui.FileQueueTable.java
/** * Set up and display the file queue table *//*w w w . java 2 s.c o m*/ FileQueueTable() { // ----- Variables ----- // Debug Borders Boolean debugBorders = false; // Size of the add/remove/refresh buttons (which are square). int buttonSize = 40; // Add graphic for the refresh button //String refreshIcon = "gfx/recycled.png"; // Add graphic for add button String addIcon = "gfx/add.png"; // Remove graphics for remove button String removeIcon = "gfx/remove.png"; // Width of the status columns int statusWidth = 100; // ----- GUI Layout Elements ----- // Start layout here setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); setBorder(BorderFactory.createEmptyBorder(6, 5, 9, 8)); JPanel buttonPanel = new JPanel(); if (debugBorders == true) buttonPanel.setBorder(BorderFactory.createLineBorder(Color.red, 1)); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.PAGE_AXIS)); // refreshBtn = addButton("+", refreshIcon, null); // refreshBtn.setMaximumSize(new Dimension(buttonSize, buttonSize)); // refreshBtn.setPreferredSize(new Dimension(buttonSize, buttonSize)); // refreshBtn.setMinimumSize(new Dimension(buttonSize, buttonSize)); // refreshBtn.setSize(new Dimension(buttonSize, buttonSize)); // refreshBtn.setActionCommand(Actions.REFRESH); // refreshBtn.addActionListener(this); addBtn = GuiCommonElements.addBasicButton(null, addIcon, null); addBtn.setMaximumSize(new Dimension(buttonSize, buttonSize)); addBtn.setPreferredSize(new Dimension(buttonSize, buttonSize)); addBtn.setMinimumSize(new Dimension(buttonSize, buttonSize)); addBtn.setSize(new Dimension(buttonSize, buttonSize)); addBtn.setActionCommand(FileQueueHandler.ADD); addBtn.addActionListener(this); addBtn.setToolTipText("Add files to the import queue."); removeBtn = GuiCommonElements.addBasicButton(null, removeIcon, null); removeBtn.setMaximumSize(new Dimension(buttonSize, buttonSize)); removeBtn.setPreferredSize(new Dimension(buttonSize, buttonSize)); removeBtn.setMinimumSize(new Dimension(buttonSize, buttonSize)); removeBtn.setSize(new Dimension(buttonSize, buttonSize)); removeBtn.setActionCommand(FileQueueHandler.REMOVE); removeBtn.addActionListener(this); removeBtn.setToolTipText("Remove files from the import queue."); buttonPanel.add(Box.createRigidArea(new Dimension(0, 60))); //buttonPanel.add(refreshBtn); buttonPanel.add(Box.createVerticalGlue()); buttonPanel.add(addBtn); buttonPanel.add(Box.createRigidArea(new Dimension(0, 5))); buttonPanel.add(removeBtn); buttonPanel.add(Box.createVerticalGlue()); buttonPanel.add(Box.createRigidArea(new Dimension(0, 60))); add(buttonPanel); add(Box.createRigidArea(new Dimension(5, 0))); JPanel queuePanel = new JPanel(); if (debugBorders == true) queuePanel.setBorder(BorderFactory.createLineBorder(Color.red, 1)); queuePanel.setLayout(new BoxLayout(queuePanel, BoxLayout.PAGE_AXIS)); //queuePanel.add(Box.createRigidArea(new Dimension(0,10))); JPanel labelPanel = new JPanel(); labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.LINE_AXIS)); JLabel label = new JLabel("Import Queue:"); labelPanel.add(label); labelPanel.add(Box.createHorizontalGlue()); groupBtn = GuiCommonElements.addBasicButton("Group: ", null, "Current Group"); groupBtn.setToolTipText("The user group you are logged into."); //groupBtn.setEnabled(false); labelPanel.add(groupBtn); queuePanel.add(labelPanel); queuePanel.add(Box.createRigidArea(new Dimension(0, 5))); TableColumnModel cModel = getQueue().getColumnModel(); headerCellRenderer = new MyTableHeaderRenderer(); fileCellRenderer = new LeftDotRenderer(); dpCellRenderer = new CenterTextRenderer(); statusCellRenderer = new CenterTextRenderer(); // Create a custom header for the table cModel.getColumn(0).setHeaderRenderer(headerCellRenderer); cModel.getColumn(1).setHeaderRenderer(headerCellRenderer); cModel.getColumn(2).setHeaderRenderer(headerCellRenderer); cModel.getColumn(0).setCellRenderer(fileCellRenderer); cModel.getColumn(1).setCellRenderer(dpCellRenderer); cModel.getColumn(2).setCellRenderer(statusCellRenderer); // Set the width of the status column TableColumn statusColumn = getQueue().getColumnModel().getColumn(2); statusColumn.setPreferredWidth(statusWidth); statusColumn.setMaxWidth(statusWidth); statusColumn.setMinWidth(statusWidth); SelectionListener listener = new SelectionListener(getQueue()); getQueue().getSelectionModel().addListSelectionListener(listener); //queue.getColumnModel().getSelectionModel() // .addListSelectionListener(listener); // Hide 3rd to 6th columns TableColumnModel tcm = getQueue().getColumnModel(); TableColumn projectColumn = tcm.getColumn(6); tcm.removeColumn(projectColumn); TableColumn userPixelColumn = tcm.getColumn(6); tcm.removeColumn(userPixelColumn); TableColumn userSpecifiedNameColumn = tcm.getColumn(6); tcm.removeColumn(userSpecifiedNameColumn); TableColumn datasetColumn = tcm.getColumn(3); tcm.removeColumn(datasetColumn); TableColumn pathColumn = tcm.getColumn(3); tcm.removeColumn(pathColumn); TableColumn archiveColumn = tcm.getColumn(3); tcm.removeColumn(archiveColumn); // Add the table to the scollpane JScrollPane scrollPane = new JScrollPane(getQueue()); queuePanel.add(scrollPane); JPanel importPanel = new JPanel(); importPanel.setLayout(new BoxLayout(importPanel, BoxLayout.LINE_AXIS)); clearDoneBtn = GuiCommonElements.addBasicButton("Clear Done", null, null); clearFailedBtn = GuiCommonElements.addBasicButton("Clear Failed", null, null); importBtn = GuiCommonElements.addBasicButton("Import", null, null); importPanel.add(Box.createHorizontalGlue()); importPanel.add(clearDoneBtn); clearDoneBtn.setEnabled(false); clearDoneBtn.setActionCommand(FileQueueHandler.CLEARDONE); clearDoneBtn.addActionListener(this); clearDoneBtn.setToolTipText("Clear all 'done' entries from the import queue."); importPanel.add(Box.createRigidArea(new Dimension(0, 5))); importPanel.add(clearFailedBtn); clearFailedBtn.setEnabled(false); clearFailedBtn.setActionCommand(FileQueueHandler.CLEARFAILED); clearFailedBtn.addActionListener(this); clearFailedBtn.setToolTipText("Clear all 'failed' entries from the import queue."); importPanel.add(Box.createRigidArea(new Dimension(0, 10))); importPanel.add(importBtn); importBtn.setEnabled(false); importBtn.setActionCommand(FileQueueHandler.IMPORT); importBtn.addActionListener(this); importBtn.setToolTipText("Begin importing files."); GuiCommonElements.enterPressesWhenFocused(importBtn); queuePanel.add(Box.createRigidArea(new Dimension(0, 5))); queuePanel.add(importPanel); add(queuePanel); }
From source file:ome.formats.importer.gui.HistoryTable.java
/** * Create history table/* ww w .j ava 2 s. c om*/ * * @param viewer- GuiImporter parent */ HistoryTable(GuiImporter viewer) { this.viewer = viewer; try { historyTaskBar.addPropertyChangeListener(this); } catch (Exception ex) { log.error("Exception adding property change listener.", ex); } HistoryTableStore db = null; //HistoryDB db = null; try { db = new HistoryTableStore(); db.addObserver(this); } catch (Exception e) { db = null; log.error("Could not start history DB.", e); if (HistoryDB.alertOnce == false) { JOptionPane.showMessageDialog(null, "We were not able to connect to the history DB.\n" + "In the meantime, you will still be able to use \n" + "the importer, but the history feature will be disable.", "Warning", JOptionPane.ERROR_MESSAGE); HistoryDB.alertOnce = true; } } this.db = db; // set to layout that will maximize on resizing setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); this.setOpaque(false); // Main Panel containing all elements // Set up the main panel layout /* Disabled till #2308 fixed double mainTable[][] = {{170, 10, TableLayout.FILL, 80}, // columns { 5, 30, 35, 40, TableLayout.FILL, 35, 5}}; // rows */ double mainTable[][] = { { 170, 10, TableLayout.FILL, 90 }, // columns { 5, 30, 35, 70, TableLayout.FILL, 35, 5 } }; // rows mainPanel = GuiCommonElements.addMainPanel(this, mainTable, 0, 0, 0, 0, debug); // *****Side Panel**** double topSideTable[][] = { { TableLayout.FILL }, // columns { 20, 20, 20, 20, 35 } }; // rows topSidePanel = GuiCommonElements.addBorderedPanel(mainPanel, topSideTable, " Date Filter ", debug); String[] dateFormats = new String[1]; dateFormats[0] = DATE_FORMAT; fromDate = new JXDatePicker(); fromDate.setToolTipText("Pick a from date."); //fromDate.getEditor().setEditable(false); //fromDate.setEditable(false); fromDate.setFormats(dateFormats); toDate = new JXDatePicker(); toDate.setToolTipText("Pick a to date."); //toDate.getEditor().setEditable(false); //toDate.setEditable(false); toDate.setFormats(dateFormats); fromLabel = new JLabel("From (yy/mm/dd):"); topSidePanel.add(fromLabel, "0,0"); topSidePanel.add(fromDate, "0,1"); toLabel = new JLabel("To (yy/mm/dd):"); topSidePanel.add(toLabel, "0,2"); topSidePanel.add(toDate, "0,3"); double bottomSideTable[][] = { { TableLayout.FILL }, // columns { TableLayout.FILL } }; // rows historyTaskBar.addTaskPane("Today", historyTaskBar.getList(todayList)); historyTaskBar.addTaskPane("Yesterday", historyTaskBar.getList(yesterdayList)); historyTaskBar.addTaskPane("This Week", historyTaskBar.getList(thisWeekList)); historyTaskBar.addTaskPane("Last Week", historyTaskBar.getList(lastWeekList)); historyTaskBar.addTaskPane("This Month", historyTaskBar.getList(thisMonthList)); bottomSidePanel = GuiCommonElements.addBorderedPanel(mainPanel, bottomSideTable, " Quick Date ", debug); /* JPanel taskPanel = new JPanel( new BorderLayout() ); JScrollPane taskScrollPane = new JScrollPane(); taskScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); taskScrollPane.getViewport().add(historyTaskBar); taskPanel.add(taskScrollPane); bottomSidePanel.add(taskPanel, "f,f"); taskPanel.validate(); */ bottomSidePanel.add(historyTaskBar, "0,0"); clearBtn = GuiCommonElements.addIconButton(mainPanel, "Wipe History", clearIcon, 130, 32, (int) 'S', "Click here to clear your history log.", "0,5,C,C", debug); clearBtn.setActionCommand(HistoryHandler.CLEARHISTORY); clearBtn.addActionListener(this); // *****Top right most row containing search field and buttons***** /*// Disabled till #2308 fixed searchField = GuiCommonElements.addTextField(mainPanel, "Name Filter: ", "*.*", 'N', "Type in a file name to search for here.", "", TableLayout.PREFERRED, "2,1, 0, 0", debug); */ searchField = new JTextField("*.*"); searchField.setVisible(false); searchBtn = GuiCommonElements.addButton(topSidePanel, "Search", 'S', "Click here to search", "0,4,C,C", debug); searchBtn.setActionCommand(HistoryHandler.HISTORYSEARCH); searchBtn.addActionListener(this); // *****Middle right row containing the filter options***** // Since this panel has a different layout, use a new panel for it /* Disabled till #2308 fixed // Set up the filterTable layout double filterTable[][] = {{100, 80, 80, 80, 90, TableLayout.FILL}, // columns { 30 }}; // rows filterPanel = GuiCommonElements.addPlanePanel(mainPanel, filterTable, debug); filterLabel = GuiCommonElements.addTextPane(filterPanel, "Status Filters: ", "0,0,r,c", debug); doneCheckBox = GuiCommonElements.addCheckBox(filterPanel, "Done", "1,0,L,C", debug); failedCheckBox = GuiCommonElements.addCheckBox(filterPanel, "Failed", "2,0,L,C", debug); invalidCheckBox = GuiCommonElements.addCheckBox(filterPanel, "Invalid", "3,0,L,C", debug); pendingCheckBox = GuiCommonElements.addCheckBox(filterPanel, "Pending", "4,0,L,C", debug); // Default filters to 'on' doneCheckBox.setSelected(true); failedCheckBox.setSelected(true); invalidCheckBox.setSelected(true); pendingCheckBox.setSelected(true); doneCheckBox.addActionListener(this); failedCheckBox.addActionListener(this); invalidCheckBox.addActionListener(this); pendingCheckBox.addActionListener(this); filterPanel.setVisible(false); */ // *****Bottom right most row containing the history table***** TableColumnModel cModel = eTable.getColumnModel(); // *** remove last 4 rows from display *** TableColumn hiddenColumn = cModel.getColumn(6); cModel.removeColumn(hiddenColumn); hiddenColumn = cModel.getColumn(5); cModel.removeColumn(hiddenColumn); hiddenColumn = cModel.getColumn(4); cModel.removeColumn(hiddenColumn); MyTableHeaderRenderer myHeader = new MyTableHeaderRenderer(); // Create a custom header for the table cModel.getColumn(0).setHeaderRenderer(myHeader); cModel.getColumn(1).setHeaderRenderer(myHeader); cModel.getColumn(2).setHeaderRenderer(myHeader); cModel.getColumn(3).setHeaderRenderer(myHeader); cModel.getColumn(0).setCellRenderer(new LeftDotRenderer()); cModel.getColumn(1).setCellRenderer(new TextCellCenter()); cModel.getColumn(2).setCellRenderer(new TextCellCenter()); cModel.getColumn(3).setCellRenderer(new TextCellCenter()); // Set the width of the status column TableColumn statusColumn = eTable.getColumnModel().getColumn(3); statusColumn.setPreferredWidth(statusWidth); statusColumn.setMaxWidth(statusWidth); statusColumn.setMinWidth(statusWidth); // Set the width of the status column TableColumn dateColumn = eTable.getColumnModel().getColumn(2); dateColumn.setPreferredWidth(dateWidth); dateColumn.setMaxWidth(dateWidth); dateColumn.setMinWidth(dateWidth); // Add the table to the scollpane JScrollPane scrollPane = new JScrollPane(eTable); // disabled till #2308 fixed //reimportBtn = GuiCommonElements.addButton(filterPanel, "Reimport", 'R', "Click here to reimport selected images", "5,0,R,C", debug); reimportBtn = GuiCommonElements.addButton(mainPanel, "Reimport", 'R', "Click here to reimport selected images", "3,5,C,C", debug); reimportBtn.setEnabled(false); reimportBtn.setActionCommand(HistoryHandler.HISTORYREIMPORT); reimportBtn.addActionListener(this); // Handle the listener ListSelectionModel selectionModel = this.eTable.getSelectionModel(); selectionModel.addListSelectionListener(this); //mainPanel.add(scrollPane, "2,3,3,5"); Disabled till #2308 fixed mainPanel.add(scrollPane, "2,1,3,4"); mainPanel.add(bottomSidePanel, "0,4,0,0"); mainPanel.add(topSidePanel, "0,0,0,3"); //mainPanel.add(filterPanel, "2,2,3,1"); this.add(mainPanel); }
From source file:op.tools.SYSTools.java
public static void packColumn(JTable table, int vColIndex, int margin) { TableModel model = table.getModel(); DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel(); TableColumn col = colModel.getColumn(vColIndex); int width = 0; // Get width of column header TableCellRenderer renderer = col.getHeaderRenderer(); if (renderer == null) { renderer = table.getTableHeader().getDefaultRenderer(); }/*from w w w . jav a 2s .co m*/ Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0); width = comp.getPreferredSize().width; // Get maximum width of column data for (int r = 0; r < table.getRowCount(); r++) { renderer = table.getCellRenderer(r, vColIndex); comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, vColIndex), false, false, r, vColIndex); width = Math.max(width, comp.getPreferredSize().width); } // Add margin width += 2 * margin; // Set the width col.setPreferredWidth(width); OPDE.debug("packColumn/3: col=" + vColIndex + " width=" + width); }
From source file:org.apache.cayenne.swing.TableBinding.java
protected void resizeColumns(Object[] sampleLongValues) { TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); TableColumnModel columnModel = table.getColumnModel(); TableModel tableModel = table.getModel(); for (int i = 0; i < columnModel.getColumnCount(); i++) { TableColumn column = columnModel.getColumn(i); Component header = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0);//from w w w . jav a2 s. co m int headerWidth = header.getPreferredSize().width; if (sampleLongValues[i] != null) { Component bigCell = table.getDefaultRenderer(tableModel.getColumnClass(i)) .getTableCellRendererComponent(table, sampleLongValues[i], false, false, 0, i); int cellWidth = bigCell.getPreferredSize().width; column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } else { column.setPreferredWidth(headerWidth); } } }
From source file:org.apache.jmeter.protocol.http.visualizers.RequestViewHTTP.java
/** * Create a pane with three tables (request, params, headers) * //from ww w .j av a 2s . c o m * @return Pane to display request data */ private Component createRequestPane() { // Set up the 1st table Result with empty headers tableRequest = new JTable(requestModel); JMeterUtils.applyHiDPI(tableRequest); tableRequest.setToolTipText(JMeterUtils.getResString("textbox_tooltip_cell")); // $NON-NLS-1$ tableRequest.addMouseListener(new TextBoxDoubleClick(tableRequest)); setFirstColumnPreferredAndMaxWidth(tableRequest); RendererUtils.applyRenderers(tableRequest, RENDERERS_REQUEST); // Set up the 2nd table tableParams = new JTable(paramsModel); JMeterUtils.applyHiDPI(tableParams); tableParams.setToolTipText(JMeterUtils.getResString("textbox_tooltip_cell")); // $NON-NLS-1$ tableParams.addMouseListener(new TextBoxDoubleClick(tableParams)); TableColumn column = tableParams.getColumnModel().getColumn(0); column.setPreferredWidth(160); tableParams.getTableHeader().setDefaultRenderer(new HeaderAsPropertyRenderer()); RendererUtils.applyRenderers(tableParams, RENDERERS_PARAMS); // Set up the 3rd table tableHeaders = new JTable(headersModel); JMeterUtils.applyHiDPI(tableHeaders); tableHeaders.setToolTipText(JMeterUtils.getResString("textbox_tooltip_cell")); // $NON-NLS-1$ tableHeaders.addMouseListener(new TextBoxDoubleClick(tableHeaders)); setFirstColumnPreferredAndMaxWidth(tableHeaders); tableHeaders.getTableHeader().setDefaultRenderer(new HeaderAsPropertyRenderer()); RendererUtils.applyRenderers(tableHeaders, RENDERERS_HEADERS); // Create the split pane JSplitPane topSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, GuiUtils.makeScrollPane(tableParams), GuiUtils.makeScrollPane(tableHeaders)); topSplit.setOneTouchExpandable(true); topSplit.setResizeWeight(0.50); // set split ratio topSplit.setBorder(null); // see bug jdk 4131528 JSplitPane paneParsed = new JSplitPane(JSplitPane.VERTICAL_SPLIT, GuiUtils.makeScrollPane(tableRequest), topSplit); paneParsed.setOneTouchExpandable(true); paneParsed.setResizeWeight(0.25); // set split ratio (only 5 lines to display) paneParsed.setBorder(null); // see bug jdk 4131528 // Hint to background color on bottom tabs (grey, not blue) JPanel panel = new JPanel(new BorderLayout()); panel.add(paneParsed); return panel; }
From source file:org.apache.jmeter.protocol.http.visualizers.RequestViewHTTP.java
private void setFirstColumnPreferredAndMaxWidth(JTable table) { TableColumn column = table.getColumnModel().getColumn(0); column.setMaxWidth(300);//from w ww .j a v a2s . com column.setPreferredWidth(160); }
From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java
private JTable createTable(final ViewState state) { JTable table;/* w w w . jav a 2 s . c o m*/ final ModelGraph selected = state.getSelected(); if (selected != null) { final Vector<Vector<String>> rows = new Vector<Vector<String>>(); ConcurrentHashMap<String, String> keyToGroupMap = new ConcurrentHashMap<String, String>(); Metadata staticMet = selected.getModel().getStaticMetadata(); Metadata inheritedMet = selected.getInheritedStaticMetadata(state); Metadata completeMet = new Metadata(); if (staticMet != null) { completeMet.replaceMetadata(staticMet.getSubMetadata(state.getCurrentMetGroup())); } if (selected.getModel().getExtendsConfig() != null) { for (String configGroup : selected.getModel().getExtendsConfig()) { Metadata extendsMetadata = state.getGlobalConfigGroups().get(configGroup).getMetadata() .getSubMetadata(state.getCurrentMetGroup()); for (String key : extendsMetadata.getAllKeys()) { if (!completeMet.containsKey(key)) { keyToGroupMap.put(key, configGroup); completeMet.replaceMetadata(key, extendsMetadata.getAllMetadata(key)); } } } } if (inheritedMet != null) { Metadata inheritedMetadata = inheritedMet.getSubMetadata(state.getCurrentMetGroup()); for (String key : inheritedMetadata.getAllKeys()) { if (!completeMet.containsKey(key)) { keyToGroupMap.put(key, "__inherited__"); completeMet.replaceMetadata(key, inheritedMetadata.getAllMetadata(key)); } } } List<String> keys = completeMet.getAllKeys(); Collections.sort(keys); for (String key : keys) { if (key.endsWith("/envReplace")) { continue; } String values = StringUtils.join(completeMet.getAllMetadata(key), ","); Vector<String> row = new Vector<String>(); row.add(keyToGroupMap.get(key)); row.add(key); row.add(values); row.add(Boolean.toString(Boolean.parseBoolean(completeMet.getMetadata(key + "/envReplace")))); rows.add(row); } table = new JTable();// rows, new Vector<String>(Arrays.asList(new // String[] { "key", "values", "envReplace" }))); table.setModel(new AbstractTableModel() { public String getColumnName(int col) { switch (col) { case 0: return "group"; case 1: return "key"; case 2: return "values"; case 3: return "envReplace"; default: return null; } } public int getRowCount() { return rows.size() + 1; } public int getColumnCount() { return 4; } public Object getValueAt(int row, int col) { if (row >= rows.size()) { return null; } String value = rows.get(row).get(col); if (value == null && col == 3) { return "false"; } if (value == null && col == 0) { return "__local__"; } return value; } public boolean isCellEditable(int row, int col) { if (row >= rows.size()) { return selected.getModel().getStaticMetadata().containsGroup(state.getCurrentMetGroup()); } if (col == 0) { return false; } String key = rows.get(row).get(1); return key == null || (selected.getModel().getStaticMetadata() != null && selected.getModel().getStaticMetadata().containsKey(getKey(key, state))); } public void setValueAt(Object value, int row, int col) { if (row >= rows.size()) { Vector<String> newRow = new Vector<String>( Arrays.asList(new String[] { null, null, null, null })); newRow.add(col, (String) value); rows.add(newRow); } else { Vector<String> rowValues = rows.get(row); rowValues.add(col, (String) value); rowValues.remove(col + 1); } this.fireTableCellUpdated(row, col); } }); MyTableListener tableListener = new MyTableListener(state); table.getModel().addTableModelListener(tableListener); table.getSelectionModel().addListSelectionListener(tableListener); } else { table = new JTable(new Vector<Vector<String>>(), new Vector<String>(Arrays.asList(new String[] { "key", "values", "envReplace" }))); } // table.setFillsViewportHeight(true); table.setSelectionBackground(Color.cyan); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableCellRenderer cellRenderer = new TableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel field = new JLabel((String) value); if (column == 0) { field.setForeground(Color.gray); } else { if (isSelected) { field.setBorder(new EtchedBorder(1)); } if (table.isCellEditable(row, 1)) { field.setForeground(Color.black); } else { field.setForeground(Color.gray); } } return field; } }; TableColumn groupCol = table.getColumnModel().getColumn(0); groupCol.setPreferredWidth(75); groupCol.setCellRenderer(cellRenderer); TableColumn keyCol = table.getColumnModel().getColumn(1); keyCol.setPreferredWidth(200); keyCol.setCellRenderer(cellRenderer); TableColumn valuesCol = table.getColumnModel().getColumn(2); valuesCol.setPreferredWidth(300); valuesCol.setCellRenderer(cellRenderer); TableColumn envReplaceCol = table.getColumnModel().getColumn(3); envReplaceCol.setPreferredWidth(75); envReplaceCol.setCellRenderer(cellRenderer); table.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3 && DefaultPropView.this.table.getSelectedRow() != -1) { int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition()); String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state); Metadata staticMet = state.getSelected().getModel().getStaticMetadata(); override.setVisible(staticMet == null || !staticMet.containsKey(key)); delete.setVisible(staticMet != null && staticMet.containsKey(key)); tableMenu.show(DefaultPropView.this.table, e.getX(), e.getY()); } } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); return table; }
From source file:org.codinjutsu.tools.mongo.view.MongoConfigurable.java
@Nullable @Override/* w w w. j a v a2s .c o m*/ public JComponent createComponent() { JPanel mongoShellOptionsPanel = new JPanel(); mongoShellOptionsPanel.setLayout(new BoxLayout(mongoShellOptionsPanel, BoxLayout.X_AXIS)); shellPathField = createShellPathField(); mongoShellOptionsPanel.add(new JLabel("Path to Mongo executable:")); mongoShellOptionsPanel.add(shellPathField); mongoShellOptionsPanel.add(createTestButton()); mongoShellOptionsPanel.add(createFeedbackLabel()); mainPanel.add(mongoShellOptionsPanel, BorderLayout.NORTH); PanelWithButtons panelWithButtons = new PanelWithButtons() { { initPanel(); } @Nullable @Override protected String getLabelText() { return "Servers"; } @Override protected JButton[] createButtons() { return new JButton[] {}; } @Override protected JComponent createMainComponent() { table = new JBTable(tableModel); table.getEmptyText().setText("No server configuration set"); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); TableColumn autoConnectColumn = table.getColumnModel().getColumn(2); int width = table.getFontMetrics(table.getFont()).stringWidth(table.getColumnName(2)) + 10; autoConnectColumn.setPreferredWidth(width); autoConnectColumn.setMaxWidth(width); autoConnectColumn.setMinWidth(width); return ToolbarDecorator.createDecorator(table).setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { stopEditing(); ServerConfiguration serverConfiguration = ServerConfiguration.byDefault(); ConfigurationDialog dialog = new ConfigurationDialog(mainPanel, mongoManager, serverConfiguration); dialog.setTitle("Add a Mongo Server"); dialog.show(); if (!dialog.isOK()) { return; } configurations.add(serverConfiguration); int index = configurations.size() - 1; tableModel.fireTableRowsInserted(index, index); table.getSelectionModel().setSelectionInterval(index, index); table.scrollRectToVisible(table.getCellRect(index, 0, true)); } }).setAddActionName("addServer").setEditAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { stopEditing(); int selectedIndex = table.getSelectedRow(); if (selectedIndex < 0 || selectedIndex >= tableModel.getRowCount()) { return; } ServerConfiguration sourceConfiguration = configurations.get(selectedIndex); ServerConfiguration copiedCconfiguration = sourceConfiguration.clone(); ConfigurationDialog dialog = new ConfigurationDialog(mainPanel, mongoManager, copiedCconfiguration); dialog.setTitle("Edit a Mongo Server"); dialog.show(); if (!dialog.isOK()) { return; } configurations.set(selectedIndex, copiedCconfiguration); tableModel.fireTableRowsUpdated(selectedIndex, selectedIndex); table.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex); } }).setEditActionName("editServer").setRemoveAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { stopEditing(); int selectedIndex = table.getSelectedRow(); if (selectedIndex < 0 || selectedIndex >= tableModel.getRowCount()) { return; } TableUtil.removeSelectedItems(table); } }).setRemoveActionName("removeServer").disableUpDownActions().createPanel(); } }; mainPanel.add(panelWithButtons, BorderLayout.CENTER); return mainPanel; }
From source file:org.codinjutsu.tools.nosql.NoSqlConfigurable.java
@Nullable @Override/*w w w .ja va 2 s.co m*/ public JComponent createComponent() { JPanel databaseVendorShellOptionsPanel = new JPanel(); databaseVendorShellOptionsPanel.setLayout(new BoxLayout(databaseVendorShellOptionsPanel, BoxLayout.Y_AXIS)); mongoShellPanel = new ShellPathPanel(DatabaseVendor.MONGO, "--version"); databaseVendorShellOptionsPanel.add(mongoShellPanel); redisShellPanel = new ShellPathPanel(DatabaseVendor.REDIS, "--version"); databaseVendorShellOptionsPanel.add(redisShellPanel); mainPanel.add(databaseVendorShellOptionsPanel, BorderLayout.NORTH); PanelWithButtons panelWithButtons = new PanelWithButtons() { { initPanel(); } @Nullable @Override protected String getLabelText() { return "Servers"; } @Override protected JButton[] createButtons() { return new JButton[] {}; } @Override protected JComponent createMainComponent() { table = new JBTable(tableModel); table.getEmptyText().setText("No server configuration set"); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setDefaultRenderer(DatabaseVendor.class, new ColoredTableCellRenderer() { @Override protected void customizeCellRenderer(JTable jTable, Object value, boolean b, boolean b1, int i, int i1) { DatabaseVendor databaseVendor = (DatabaseVendor) value; this.setIcon(databaseVendor.icon); this.append(databaseVendor.name); } }); TableColumn autoConnectColumn = table.getColumnModel().getColumn(3); int autoConnectColumnWidth = table.getFontMetrics(table.getFont()) .stringWidth(table.getColumnName(3)) + 10; autoConnectColumn.setPreferredWidth(autoConnectColumnWidth); autoConnectColumn.setMaxWidth(autoConnectColumnWidth); autoConnectColumn.setMinWidth(autoConnectColumnWidth); return ToolbarDecorator.createDecorator(table).setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { stopEditing(); SelectDatabaseVendorDialog databaseVendorDialog = new SelectDatabaseVendorDialog(mainPanel); databaseVendorDialog.setTitle("Add a NoSql Server"); databaseVendorDialog.show(); if (!databaseVendorDialog.isOK()) { return; } DatabaseVendor selectedDatabaseVendor = databaseVendorDialog.getSelectedDatabaseVendor(); ServerConfiguration serverConfiguration = databaseVendorClientManager .get(selectedDatabaseVendor).defaultConfiguration(); serverConfiguration.setDatabaseVendor(selectedDatabaseVendor); ConfigurationDialog dialog = new ConfigurationDialog(mainPanel, serverConfigurationPanelFactory, serverConfiguration); dialog.setTitle("Add a NoSql Server"); dialog.show(); if (!dialog.isOK()) { return; } configurations.add(serverConfiguration); int index = configurations.size() - 1; tableModel.fireTableRowsInserted(index, index); table.getSelectionModel().setSelectionInterval(index, index); table.scrollRectToVisible(table.getCellRect(index, 0, true)); } }).setAddActionName("addServer").setEditAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { stopEditing(); int selectedIndex = table.getSelectedRow(); if (selectedIndex < 0 || selectedIndex >= tableModel.getRowCount()) { return; } ServerConfiguration sourceConfiguration = configurations.get(selectedIndex); ServerConfiguration copiedConfiguration = sourceConfiguration.clone(); ConfigurationDialog dialog = new ConfigurationDialog(mainPanel, serverConfigurationPanelFactory, copiedConfiguration); dialog.setTitle("Edit a NoSql Server"); dialog.show(); if (!dialog.isOK()) { return; } configurations.set(selectedIndex, copiedConfiguration); tableModel.fireTableRowsUpdated(selectedIndex, selectedIndex); table.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex); } }).setEditActionName("editServer").setRemoveAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { stopEditing(); int selectedIndex = table.getSelectedRow(); if (selectedIndex < 0 || selectedIndex >= tableModel.getRowCount()) { return; } TableUtil.removeSelectedItems(table); } }).setRemoveActionName("removeServer").disableUpDownActions().createPanel(); } }; mainPanel.add(panelWithButtons, BorderLayout.CENTER); return mainPanel; }