[Schmitzm-commits] r496 - branches/1.0-gt2-2.6/src/schmitzm/swing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Oct 23 18:56:03 CEST 2009


Author: alfonx
Date: 2009-10-23 18:56:03 +0200 (Fri, 23 Oct 2009)
New Revision: 496

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/swing/SwingUtil.java
Log:
New utility method to set column renderers and width


Modified: branches/1.0-gt2-2.6/src/schmitzm/swing/SwingUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/swing/SwingUtil.java	2009-10-23 14:19:46 UTC (rev 495)
+++ branches/1.0-gt2-2.6/src/schmitzm/swing/SwingUtil.java	2009-10-23 16:56:03 UTC (rev 496)
@@ -55,7 +55,9 @@
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
 import javax.swing.JScrollPane;
+import javax.swing.JTable;
 import javax.swing.JTree;
+import javax.swing.table.TableCellRenderer;
 import javax.swing.tree.TreeNode;
 import javax.swing.tree.TreePath;
 
@@ -429,8 +431,9 @@
 	 *            Eine Komponente des zu positionierenden Fensters oder direkt
 	 *            das {@link Window}.
 	 * @param relComp
-	 *            Fenster (parent Fenster der übergebenen Componente) zu dem das Fenster in Relation gesetzt wird (wenn
-	 *            <code>null</code> wird der gesamte Monitor verwendet)
+	 *            Fenster (parent Fenster der übergebenen Componente) zu dem das
+	 *            Fenster in Relation gesetzt wird (wenn <code>null</code> wird
+	 *            der gesamte Monitor verwendet)
 	 * @param relX
 	 *            Relationsfaktor fuer die horizontale Position (0 <
 	 *            <code>relX</code> < 1)
@@ -440,14 +443,13 @@
 	 */
 	public static void setRelativeFramePosition(Component comp,
 			Component relComp, double relX, double relY) {
-		
+
 		// Added by SK, 17.4.2009
 		Window window = SwingUtil.getParentWindow(comp);
 		relComp = getParentWindow(comp);
 
 		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
-		Dimension relSize = (relComp == null) ? screenSize : relComp
-				.getSize();
+		Dimension relSize = (relComp == null) ? screenSize : relComp.getSize();
 		Point relLocation = (relComp == null) ? new Point(0, 0) : relComp
 				.getLocation();
 
@@ -487,13 +489,12 @@
 	 */
 	public static void setRelativeFramePosition(Component comp,
 			Component relWindow, int type, int position) {
-		
-		
+
 		// Added by SK, 23.10.2009
 		Window window = SwingUtil.getParentWindow(comp);
-		
+
 		relWindow = SwingUtil.getParentWindow(relWindow);
-		
+
 		if (type == BOUNDS_INNER) {
 			// An den inneren Grenzen des Frames ausrichten
 			double relX = 0;
@@ -555,7 +556,7 @@
 			case NORTHWEST:
 			case NORTHEAST:
 				loc.y = relLocation.y; // Oben bündig ist schöner, oder?
-//				loc.y = relLocation.y - window.getHeight();
+				// loc.y = relLocation.y - window.getHeight();
 				break;
 			case SOUTH:
 			case SOUTHWEST:
@@ -1027,4 +1028,30 @@
 
 	}
 
+	/**
+	 * Allows to define a renderer and min- and max width of a column with just
+	 * one line of code ;-)
+	 * 
+	 * @param table 
+	 * @param modelIdx column index in model
+	 * @param cellRenderer <code>null</code> allowed
+	 * @param minwidth <code>null</code> allowed
+	 * @param prefwidth <code>null</code> allowed
+	 * @param maxwidth <code>null</code> allowed
+	 */
+	public static void setColumnLook(JTable table, Integer modelIdx,
+			TableCellRenderer cellRenderer, Integer minWidth, Integer preferredWidth, Integer maxWidth) {
+
+		int idx = table.convertColumnIndexToView(modelIdx);
+		if (cellRenderer != null)
+			table.getColumnModel().getColumn(idx).setCellRenderer(cellRenderer);
+		if (minWidth != null)
+			table.getColumnModel().getColumn(idx).setMinWidth(minWidth);
+		if (preferredWidth!= null)
+			table.getColumnModel().getColumn(idx).setPreferredWidth(preferredWidth);
+		if (maxWidth != null)
+			table.getColumnModel().getColumn(idx).setMaxWidth(maxWidth);
+
+	}
+
 }



More information about the Schmitzm-commits mailing list