Java examples for Swing:JTable Renderer
Fixes the orientation of the default JTable renderers (for Object, Number and Boolean) to match that of the current Locale (e.g.
/*/*from ww w . ja v a2s . c om*/ * 09/08/2005 * * UIUtil.java - Utility methods for org.fife.ui classes. * Copyright (C) 2005 Robert Futrell * http://fifesoft.com/rtext * Licensed under a modified BSD license. * See the included license file for details. */ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.ComponentOrientation; import java.awt.Container; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.GridLayout; import java.awt.LayoutManager; import java.awt.RenderingHints; import java.awt.Toolkit; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.lang.reflect.Method; import java.net.URI; import java.net.URISyntaxException; import java.util.Locale; import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; import javax.swing.BorderFactory; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTable; import javax.swing.JTree; import javax.swing.KeyStroke; import javax.swing.ListCellRenderer; import javax.swing.Spring; import javax.swing.SpringLayout; import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.plaf.BorderUIResource; import javax.swing.plaf.UIResource; import javax.swing.table.TableCellRenderer; public class Main{ /** * Fixes the orientation of the default JTable renderers (for Object, * Number and Boolean) to match that of the current <code>Locale</code> * (e.g. <code>ComponentOrientation.getOrientation(table.getLocale())</code>). * This is needed because <code>DefaultTableCellRenderer</code> does not * do this, even though <code>DefaultListCellRenderer</code> and * <code>DefaultTreeCellRenderer</code> do.<p> * * See Sun bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6333197 * for more information. * * @param table The table to update. */ public static void fixJTableRendererOrientations(JTable table) { ComponentOrientation o = ComponentOrientation.getOrientation(table .getLocale()); TableCellRenderer r = table.getDefaultRenderer(Object.class); if (r instanceof Component) { // Never null for JTable Component c = (Component) r; c.setComponentOrientation(o); } r = table.getDefaultRenderer(Number.class); if (r instanceof Component) { // Never null for JTable Component c = (Component) r; c.setComponentOrientation(o); } r = table.getDefaultRenderer(Boolean.class); if (r instanceof Component) { // Never null for JTable Component c = (Component) r; c.setComponentOrientation(o); } if (table.getTableHeader() != null) { r = table.getTableHeader().getDefaultRenderer(); if (r instanceof Component) { ((Component) r).applyComponentOrientation(o); } else if (r instanceof FileExplorerTableModel.SortableHeaderRenderer) { r = ((FileExplorerTableModel.SortableHeaderRenderer) r) .getDelegateRenderer(); if (r instanceof Component) { ((Component) r).applyComponentOrientation(o); } } } } }