implements TableCellRenderer : JTable Renderer Editor « Swing « Java Tutorial

Java Tutorial
1. Language
2. Data Type
3. Operators
4. Statement Control
5. Class Definition
6. Development
7. Reflection
8. Regular Expressions
9. Collections
10. Thread
11. File
12. Generics
13. I18N
14. Swing
15. Swing Event
16. 2D Graphics
17. SWT
18. SWT 2D Graphics
19. Network
20. Database
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web Services SOA
27. EJB3
28. Spring
29. PDF
30. Email
31. J2ME
32. J2EE Application
33. XML
34. Design Pattern
35. Log
36. Security
37. Apache Common
38. Ant
39. JUnit
Java
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » Swing » JTable Renderer Editor 
14. 60. 5. implements TableCellRenderer
implements TableCellRenderer
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

public class EvenOddRowCellRenderer extends JFrame {
  DefaultTableModel tmodel = new DefaultTableModel(new Object[][] { { "some""text" },
      "any""text" }"even""more" }"text""strings" }"and""other" },
      "text""values" } }new Object[] { "Column 1""Column 2" });


  public EvenOddRowCellRenderer() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable table = new JTable(tmodel);
    table.setDefaultRenderer(Object.class, new MyRenderer());
    getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
    pack();
  }

  public static void main(String arg[]) {
    new EvenOddRowCellRenderer().setVisible(true);
  }
}

class MyRenderer implements TableCellRenderer {
  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
      boolean hasFocus, int row, int column) {
    JTextField editor = new JTextField();
    if (value != null)
      editor.setText(value.toString());
    editor.setBackground((row % == 0? Color.white : Color.cyan);
    return editor;
  }
}
14. 60. JTable Renderer Editor
14. 60. 1. Get Default cell Renderer
14. 60. 2. Get Default Cell Editor
14. 60. 3. Default Editors and Renderers
14. 60. 4. Rendering Table Cells: To install the renderer as the default renderer for the JTable for Object.classRendering Table Cells: To install the renderer as the default renderer for the JTable for Object.class
14. 60. 5. implements TableCellRendererimplements TableCellRenderer
14. 60. 6. extends DefaultCellEditorextends DefaultCellEditor
14. 60. 7. Cell Renderer for the Gender ColumnCell Renderer for the Gender Column
14. 60. 8. Demonstrates the editable property of Swing tables.Demonstrates the editable property of Swing tables.
14. 60. 9. An Editor for the Gender ColumnAn Editor for the Gender Column
14. 60. 10. ColorChooserEditor
14. 60. 11. Using a JComboBox in a Cell in a JTable Component
14. 60. 12. Editing Table Cells: JComboBox As Table Cell RendererEditing Table Cells: JComboBox As Table Cell Renderer
14. 60. 13. Using a List JSpinner as a Cell Editor in a JTable Component
14. 60. 14. Using default Boolean value cell editor and rendererUsing default Boolean value cell editor and renderer
14. 60. 15. Creating a Class-Based Custom Cell Renderer in a JTable Component
14. 60. 16. Creating a Custom Cell Renderer in a JTable Component
14. 60. 17. Preventing Invalid Values in a Cell in a JTable Component
14. 60. 18. Using Built-In Cell Renderers and Editors in a JTable Component
14. 60. 19. Save the current value in the cell being edited and stops the editing process
14. 60. 20. Discard any changes made by the user and stops the editing process
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.