Java Code Examples for javax.swing.JTable#setBackground()
The following examples show how to use
javax.swing.JTable#setBackground() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DrawGridLinesTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void checkTableGridLines() { TableModel dataModel = new AbstractTableModel() { public int getColumnCount() { return 10; } public int getRowCount() { return 10; } public Object getValueAt(int row, int col) { return " "; } }; DefaultTableCellRenderer r = new DefaultTableCellRenderer(); r.setOpaque(true); r.setBackground(CELL_RENDERER_BACKGROUND_COLOR); JTable table = new JTable(dataModel); table.setSize(WIDTH, HEIGHT); table.setDefaultRenderer(Object.class, r); table.setGridColor(GRID_COLOR); table.setShowGrid(true); table.setShowHorizontalLines(true); table.setShowVerticalLines(true); table.setBackground(TABLE_BACKGROUND_COLOR); checkTableGridLines(table); }
Example 2
Source File: AttrTable.java From Logisim with GNU General Public License v3.0 | 5 votes |
public AttrTable(Window parent) { super(new BorderLayout()); this.parent = parent; titleEnabled = true; title = new TitleLabel(); title.setHorizontalAlignment(SwingConstants.CENTER); title.setVerticalAlignment(SwingConstants.CENTER); tableModel = new TableModelAdapter(parent, NULL_ATTR_MODEL); table = new JTable(tableModel); table.setDefaultEditor(Object.class, editor); table.setTableHeader(null); table.setRowHeight(20); Font baseFont = title.getFont(); int titleSize = Math.round(baseFont.getSize() * 1.2f); Font titleFont = baseFont.deriveFont((float) titleSize).deriveFont(Font.BOLD); title.setFont(titleFont); Color bgColor = new Color(240, 240, 240); setBackground(bgColor); table.setBackground(bgColor); Object renderer = table.getDefaultRenderer(String.class); if (renderer instanceof JComponent) { ((JComponent) renderer).setBackground(Color.WHITE); } JScrollPane tableScroll = new JScrollPane(table); this.add(title, BorderLayout.PAGE_START); this.add(tableScroll, BorderLayout.CENTER); LocaleManager.addLocaleListener(this); localeChanged(); }
Example 3
Source File: GameStatisticsGUI.java From Carcassonne with Eclipse Public License 2.0 | 5 votes |
private void buildTable(Round round) { table = new JTable(new GameStatisticsModel(round)); // Columns: TableColumnModel model = table.getColumnModel(); CellRenderer renderer = new CellRenderer(round); for (int i = 0; i < model.getColumnCount(); i++) { model.getColumn(i).setCellRenderer(renderer); } // Header: JTableHeader header = table.getTableHeader(); header.setDefaultRenderer(new HeaderRenderer()); header.setReorderingAllowed(false); table.setBackground(BODY_COLOR); }
Example 4
Source File: TableUtils.java From lucene-solr with Apache License 2.0 | 5 votes |
public static void setEnabled(JTable table, boolean enabled) { table.setEnabled(enabled); if (enabled) { table.setRowSelectionAllowed(true); table.setForeground(Color.black); table.setBackground(Color.white); } else { table.setRowSelectionAllowed(false); table.setForeground(Color.gray); table.setBackground(Color.lightGray); } }
Example 5
Source File: DrawGridLInesTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private static void checkTableGridLines() { TableModel dataModel = new AbstractTableModel() { public int getColumnCount() { return 10; } public int getRowCount() { return 10; } public Object getValueAt(int row, int col) { return " "; } }; DefaultTableCellRenderer r = new DefaultTableCellRenderer(); r.setOpaque(true); r.setBackground(CELL_RENDERER_BACKGROUND_COLOR); JTable table = new JTable(dataModel); table.setSize(WIDTH, HEIGHT); table.setDefaultRenderer(Object.class, r); table.setGridColor(GRID_COLOR); table.setShowGrid(true); table.setShowHorizontalLines(true); table.setShowVerticalLines(true); table.setBackground(TABLE_BACKGROUND_COLOR); checkTableGridLines(table); }
Example 6
Source File: JTableFactory.java From WorldGrower with GNU General Public License v3.0 | 5 votes |
public static void setTableProperties(JTable table) { table.setBackground(ColorPalette.DARK_BACKGROUND_COLOR); table.setForeground(ColorPalette.FOREGROUND_COLOR); table.setSelectionBackground(ColorPalette.DARK_BACKGROUND_COLOR.brighter()); table.setSelectionForeground(ColorPalette.FOREGROUND_COLOR.brighter()); table.setFont(Fonts.FONT); table.getTableHeader().setDefaultRenderer(new DefaultHeaderRenderer(table.getTableHeader().getDefaultRenderer())); }
Example 7
Source File: Main_CustomersFrame.java From Hotel-Properties-Management-System with GNU General Public License v2.0 | 4 votes |
public Main_CustomersFrame() { this.setAutoscrolls(true); this.setMinimumSize(new Dimension(800, 600)); /*make it default size of frame maximized */ this.setMaximumSize(new Dimension(1000, 900)); this.setBorder(new SoftBevelBorder(BevelBorder.RAISED, null, null, null, null)); setLayout(new BorderLayout(0, 0)); bean = LocaleBean.getInstance(); loggingEngine = LoggingEngine.getInstance(); componentOrientation = new ChangeComponentOrientation(); componentOrientation.setThePanel(this); searchPanel.setDoubleBuffered(false); searchPanel.setAutoscrolls(true); add(searchPanel, BorderLayout.NORTH); searchPanel.setPreferredSize(new Dimension(10, 30)); lblTableFilter = new JLabel("Type to search : "); lblTableFilter.setForeground(new Color(178, 34, 34)); lblTableFilter.setSize(new Dimension(130, 25)); lblTableFilter.setPreferredSize(new Dimension(130, 22)); lblTableFilter.setHorizontalTextPosition(SwingConstants.CENTER); lblTableFilter.setAutoscrolls(true); lblTableFilter.setHorizontalAlignment(SwingConstants.LEFT); lblTableFilter.setFont(new Font("Dialog", Font.BOLD, 15)); searchFilterField = new JTextField(); searchFilterField.setDragEnabled(true); searchFilterField.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, new Color(0, 191, 255), null, null, null)); searchFilterField.setPreferredSize(new Dimension(200, 22)); searchFilterField.setIgnoreRepaint(true); searchFilterField.setColumns(10); searchFilterField.setFont(new Font("Dialog", Font.BOLD, 13)); searchFilterField.setHorizontalAlignment(SwingConstants.LEFT); GroupLayout gl_searchPanel = new GroupLayout(searchPanel); gl_searchPanel.setHorizontalGroup( gl_searchPanel.createParallelGroup(Alignment.LEADING) .addGroup(gl_searchPanel.createSequentialGroup() .addContainerGap() .addComponent(lblTableFilter, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(searchFilterField, GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE) .addGap(118)) ); gl_searchPanel.setVerticalGroup( gl_searchPanel.createParallelGroup(Alignment.LEADING) .addGroup(gl_searchPanel.createSequentialGroup() .addGap(5) .addGroup(gl_searchPanel.createParallelGroup(Alignment.BASELINE) .addComponent(lblTableFilter, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(searchFilterField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); searchPanel.setLayout(gl_searchPanel); searchFilterField.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { final String searchedWord = searchFilterField.getText(); filter(searchedWord); } }); scrollPane = new JScrollPane(); add(scrollPane); //populate main table model with custom method populateMainTable(model); customerTable = new JTable(model); customerTable.setFillsViewportHeight(true); customerTable.setRowSelectionAllowed(true); THR.setHorizontalAlignment(SwingConstants.CENTER); customerTable.setDefaultRenderer(Object.class, renderer); customerTable.getTableHeader().setDefaultRenderer(THR); customerTable.setFont(new Font("Dialog", Font.PLAIN, 14)); customerTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); customerTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); customerTable.setBackground(new Color(245, 245, 245)); customerTable.addMouseListener(openCustomerListener()); scrollPane.setViewportView(customerTable); //change component orientation with locale. if (bean.getLocale().toString().equals("ar_IQ")) { componentOrientation.changeOrientationOfJPanelToRight(); } else { componentOrientation.changeOrientationOfJPanelToLeft(); } //inject action event to Customers detail window to save all changes custWindow.setActionListener(saveChanges()); this.setVisible(true); }
Example 8
Source File: TableEditorsDemo.java From LGoodDatePicker with MIT License | 4 votes |
/** * Constructor, Set up the table instance, and add the table editors to the table. */ public TableEditorsDemo() { // Use a grid layout for the panel. super(new GridLayout(1, 0)); // This decides how many clicks are required to edit a cell in the table editors demo. // (Set this to 1 or 2 clicks, as desired.) int clickCountToEdit = 1; // Create the table and the scroll pane. JTable table = new JTable(new DemoTableModel()); JScrollPane scrollPane = new JScrollPane(table); this.add(scrollPane); // Set a background color for the table. Note that by default, the picker table editors // will match the table background color. This is expected behavior for table editors. // Color matching can be turned off if desired, from the table editor class constructors. table.setBackground(new Color(190, 240, 255)); // Set all the default table editors to start with the desired number of clicks. // The default table editors are the ones supplied by the JTable class. InternalUtilities.setDefaultTableEditorsClicks(table, clickCountToEdit); // Add table renderers and editors for the LocalDate, LocalTime, and LocalDateTime types. // // Note: The editors and renders for each type should be separate instances of the // matching table editor class. Don't use the same instance as both a renderer and editor. // If you did, it would be immediately obvious because the cells would not render properly. table.setDefaultRenderer(LocalDate.class, new DateTableEditor()); DateTableEditor dateEdit = new DateTableEditor(); dateEdit.clickCountToEdit = clickCountToEdit; table.setDefaultEditor(LocalDate.class, dateEdit); table.setDefaultRenderer(LocalTime.class, new TimeTableEditor()); TimeTableEditor timeEdit = new TimeTableEditor(); timeEdit.clickCountToEdit = clickCountToEdit; table.setDefaultEditor(LocalTime.class, timeEdit); table.setDefaultRenderer(LocalDateTime.class, new DateTimeTableEditor()); DateTimeTableEditor dateTimeEdit = new DateTimeTableEditor(); dateTimeEdit.clickCountToEdit = clickCountToEdit; table.setDefaultEditor(LocalDateTime.class, dateTimeEdit); // Explicitly set the default editor instance (data type) for each column, by looking at // the most common data type found in each column. zSetAllColumnEditorsAndRenderers(table); // Set the width of the DateTime column to be a bit bigger than the rest. table.getColumnModel().getColumn(DemoTableModel.dateTimeColumnIndex).setPreferredWidth(180); }
Example 9
Source File: PropriedadesSistema.java From JCEditor with GNU General Public License v2.0 | 4 votes |
/** * O construtor se encarrega de exibir todo o diálogo * O método getProperty(), da classe System foi utilizado para obter as informações do sistema */ public PropriedadesSistema() { setTitle("Sobre este Computador"); tabela = new JTable(); tabela.setEnabled(false); tabela.setShowHorizontalLines(false); tabela.setShowVerticalLines(false); tabela.setBackground(new Color(238, 238, 238)); label = new JLabel("Informações"); label.setFont(new Font("Roboto Light", Font.PLAIN, 28)); tabela.setModel(new DefaultTableModel( new Object[][] { {"Sistema Operacional", System.getProperty("os.name") + " " + System.getProperty("os.version")}, {"Arquitetura", System.getProperty("os.arch")}, {"Usuário", System.getProperty("user.name")}, {"Idioma", loc.getDisplayLanguage()}, {"Versão do Java", System.getProperty("java.version")}, {"Pasta de instalação do Java", System.getProperty("java.home")}, {"Class Path", System.getProperty("java.class.path")}, }, new String[] {null, null} )); tabela.setBorder(BorderFactory.createTitledBorder( null, null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Roboto Light", 1, 14) )); this.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent ev) { if (ev.getKeyCode() == KeyEvent.VK_ESCAPE) { PropriedadesSistema.this.dispose(); } } }); this.getContentPane().add(BorderLayout.NORTH, label); this.getContentPane().add(BorderLayout.CENTER, tabela); this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); this.setResizable(false); this.setSize(397, 175);//145 this.setLocationRelativeTo(null); this.setModal(true); this.setVisible(true); }
Example 10
Source File: UIRes.java From RipplePower with Apache License 2.0 | 4 votes |
public static void addStyle(JTable jTable) { jTable.setForeground(fontColor); jTable.setBackground(Color.WHITE); jTable.setFont(GraphicsUtils.getFont("Monospaced", 0, 13)); }