List of usage examples for javax.swing JTable setDefaultRenderer
public void setDefaultRenderer(Class<?> columnClass, TableCellRenderer renderer)
TableColumn
. From source file:MainClass.java
public MainClass() { super("Customer Editor Test"); setSize(600, 160);//from ww w . j a v a2 s . c om setDefaultCloseOperation(EXIT_ON_CLOSE); MixerModel test = new MixerModel(); JTable jt = new JTable(test); jt.setDefaultRenderer(Volume.class, new VolumeRenderer()); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:FileTable2.java
public FileTable2() { super("Custom TableModel Test"); setSize(300, 200);//from www. j a va2 s . co m setDefaultCloseOperation(EXIT_ON_CLOSE); FileModel fm = new FileModel(); JTable jt = new JTable(fm); jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); jt.setColumnSelectionAllowed(true); jt.setDefaultRenderer(Number.class, new BigRenderer(1000)); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:IsEDTExample.java
public IsEDTExample() { JTable table = new JTable(tableModel); table.setRowHeight(100);//from w ww . ja va2s . com table.setDefaultRenderer(Object.class, new ColorRenderer()); add(table); add(new JLabel("Thread Color Shade:")); ButtonGroup group = new ButtonGroup(); JRadioButton redOption = new JRadioButton("Red"); group.add(redOption); redOption.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { threadShade = RED; } }); JRadioButton blueOption = new JRadioButton("Blue"); group.add(blueOption); blueOption.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { threadShade = BLUE; } }); JRadioButton greenOption = new JRadioButton("Green"); group.add(greenOption); greenOption.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { threadShade = GREEN; } }); redOption.setSelected(true); this.threadShade = RED; add(redOption); add(greenOption); add(blueOption); add(new JButton(new RandomColorAction())); this.keepRunning = true; this.colorShadeThread = new Thread(new RandomColorShadeRunnable()); this.colorShadeThread.start(); }
From source file:MainClass.java
public MainClass() { super("Customer Editor Test"); setSize(600, 160);/*from ww w . ja v a 2 s.c om*/ setDefaultCloseOperation(EXIT_ON_CLOSE); MixerModel test = new MixerModel(); JTable jt = new JTable(test); jt.setDefaultRenderer(Volume.class, new VolumeRenderer()); jt.setDefaultEditor(Volume.class, new VolumeEditor()); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:edu.ku.brc.specify.tasks.subpane.wb.ImportDataFileInfo.java
/** * shows modified (truncated) data after import *///w w w.ja va 2s . co m protected void showModifiedData() { if (importer.getTruncations().size() > 0) { JPanel mainPane = new JPanel(new BorderLayout()); JLabel msg = createLabel(getResourceString("WB_TRUNCATIONS")); msg.setFont(msg.getFont().deriveFont(Font.BOLD)); mainPane.add(msg, BorderLayout.NORTH); String[] heads = new String[3]; String[][] vals = new String[importer.getTruncations().size()][3]; heads[0] = getResourceString("WB_ROW"); heads[1] = getResourceString("WB_COLUMN"); heads[2] = getResourceString("WB_TRUNCATED"); int row = 0; for (DataImportTruncation trunc : importer.getTruncations()) { vals[row][0] = String.valueOf(trunc.getRow()); vals[row][1] = trunc.getColHeader(); if (vals[row][1].equals("")) { vals[row][1] = String.valueOf(trunc.getCol() + 1); } vals[row++][2] = trunc.getExcluded(); } JTable mods = new JTable(vals, heads); mods.setDefaultRenderer(String.class, new BiColorTableCellRenderer(false)); mainPane.add(UIHelper.createScrollPane(mods), BorderLayout.CENTER); CustomFrame cwin = new CustomFrame(getResourceString(MODIFIED_IMPORT_DATA), CustomFrame.OKHELP, mainPane); cwin.setHelpContext("WorkbenchImportData"); //help context could be more specific cwin.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); UIHelper.centerAndShow(cwin); } if (importer.getMessages().size() > 0) { JPanel mainPane = new JPanel(new BorderLayout()); JTextArea msgs = new JTextArea(); msgs.setRows(importer.getMessages().size()); for (String msg : importer.getMessages()) { msgs.append(msg); msgs.append("\n"); } mainPane.add(msgs, BorderLayout.CENTER); CustomFrame cwin = new CustomFrame(getResourceString(MODIFIED_IMPORT_DATA), CustomFrame.OKHELP, mainPane); cwin.setHelpContext("WorkbenchImportData"); //help context could be more specific cwin.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); UIHelper.centerAndShow(cwin); } }
From source file:MixerTest2.java
public MixerTest2() { super("Customer Editor Test"); setSize(600, 160);//from www .j av a2 s . c om setDefaultCloseOperation(EXIT_ON_CLOSE); MixerModel test = new MixerModel(); test.dump(); JTable jt = new JTable(test); jt.setDefaultRenderer(Volume.class, new VolumeRenderer()); jt.setDefaultEditor(Volume.class, new VolumeEditor()); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:TableCellRenderTest.java
public TableCellRenderFrame() { setTitle("TableCellRenderTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); TableModel model = new PlanetTableModel(); JTable table = new JTable(model); table.setRowSelectionAllowed(false); // set up renderers and editors table.setDefaultRenderer(Color.class, new ColorTableCellRenderer()); table.setDefaultEditor(Color.class, new ColorTableCellEditor()); JComboBox moonCombo = new JComboBox(); for (int i = 0; i <= 20; i++) moonCombo.addItem(i);// w ww . j ava 2s.c o m TableColumnModel columnModel = table.getColumnModel(); TableColumn moonColumn = columnModel.getColumn(PlanetTableModel.MOONS_COLUMN); moonColumn.setCellEditor(new DefaultCellEditor(moonCombo)); moonColumn.setHeaderRenderer(table.getDefaultRenderer(ImageIcon.class)); moonColumn.setHeaderValue(new ImageIcon("Moons.gif")); // show table table.setRowHeight(100); add(new JScrollPane(table), BorderLayout.CENTER); }
From source file:components.TableDialogEditDemo.java
public TableDialogEditDemo() { super(new GridLayout(1, 0)); JTable table = new JTable(new MyTableModel()); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true);// w ww. j a va 2 s .c o m //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Set up renderer and editor for the Favorite Color column. table.setDefaultRenderer(Color.class, new ColorRenderer(true)); table.setDefaultEditor(Color.class, new ColorEditor()); //Add the scroll pane to this panel. add(scrollPane); }
From source file:JTop.java
public JTop() { super(new GridLayout(1, 0)); tmodel = new MyTableModel(); JTable table = new JTable(tmodel); table.setPreferredScrollableViewportSize(new Dimension(500, 300)); // Set the renderer to format Double table.setDefaultRenderer(Double.class, new DoubleRenderer()); // Add some space table.setIntercellSpacing(new Dimension(6, 3)); table.setRowHeight(table.getRowHeight() + 4); // 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 w w w. j a v a 2s .c om }
From source file:de.codesourcery.eve.skills.ui.components.impl.planning.ResourceStatusComponent.java
@Override protected JPanel createPanel() { final JPanel result = new JPanel(); table.setFillsViewportHeight(true);/*from www . j a va2 s. com*/ table.setRowSorter(model.getRowSorter()); FixedBooleanTableCellRenderer.attach(table); table.setDefaultRenderer(Integer.class, new DefaultTableCellRenderer() { @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 (!(value instanceof Integer)) { return this; } if (column == 0) { setHorizontalAlignment(SwingConstants.LEFT); } else { setHorizontalAlignment(SwingConstants.RIGHT); } Integer amount = (Integer) value; if (amount.intValue() < 0) { if (!isSelected) { setBackground(Color.RED); } else { setBackground(table.getSelectionBackground()); } } else { setBackground(table.getBackground()); } return this; } }); addToShoppingListButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final List<ItemWithQuantity> items = model.getSelectedItems(); if (items.isEmpty()) { return; } final ShoppingListEditorComponent comp = new ShoppingListEditorComponent(title, "", items); comp.setModal(true); ComponentWrapper.wrapComponent(comp).setVisible(true); if (!comp.wasCancelled() && !comp.getShoppingList().isEmpty()) { shoppingListManager.addShoppingList(comp.getShoppingList()); getComponentCallback().dispose(ResourceStatusComponent.this); } } }); new GridLayoutBuilder() .add(new GridLayoutBuilder.VerticalGroup(new GridLayoutBuilder.Cell(new JScrollPane(table)), new GridLayoutBuilder.FixedCell(addToShoppingListButton))) .addTo(result); return result; }