📄 crmsutil.java
字号:
/* CRMS, customer relationship management system Copyright (C) 2003 Service To Youth Council This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information contact the SYC ICT department on GPL@syc.net.au 98 Kermode Street North Adelaide South Australia SA 5006 +61 (0)8 8367 0755 *//* * CRMSUtil.java * * Created on 1 April 2003, 03:02 */package crms.util;import java.util.*;import java.text.*;import javax.swing.table.*;import java.awt.event.*;import java.awt.*;import javax.swing.*;/** * * @author dmurphy */public class CRMSUtil { public static SimpleDateFormat df = new SimpleDateFormat("d MMMM, yyyy"); public static SimpleDateFormat tf = new SimpleDateFormat("h:mm a"); /** Creates a new instance of CRMSUtil */ private CRMSUtil() { } public static StringBuffer getDateXML() { Calendar cal = Calendar.getInstance(); StringBuffer buf = new StringBuffer(); buf.append(" <Date>" + df.format(cal.getTime())+ "</Date>\n"); return buf; } public static StringBuffer getTimeXML() { Calendar cal = Calendar.getInstance(); StringBuffer buf = new StringBuffer(); buf.append(" <Time>" + tf.format(cal.getTime())+ "</Time>\n"); return buf; } public static void resizeTable(JTable t) { resizeTable(t, false); } public static void resizeTable(JTable t, boolean addListener) { TableModel tm = t.getModel(); for (int i=0; i < tm.getColumnCount()-1; i++) { TableColumn tc = t.getColumnModel().getColumn(i); TableCellRenderer tcr = t.getDefaultRenderer(tm.getColumnClass(i)); int maxWidth = t.getTableHeader().getColumnModel().getColumn(i).getWidth(); for (int j=0; j < t.getRowCount(); j++) { Component c = tcr.getTableCellRendererComponent(t,tm.getValueAt(j,i),false,false,j,i); if (c.getPreferredSize().width > maxWidth) { maxWidth = c.getPreferredSize().width; } } maxWidth+=5; tc.setMaxWidth(maxWidth); tc.setPreferredWidth(maxWidth); tc.setResizable(true); } if (addListener) { final JTable copy = t; t.addComponentListener( new ComponentAdapter() { public void componentResized(ComponentEvent ev) { resizeTable(copy,false); } }); } } public static void fixGridBagLayout(GridBagLayout gbl, JPanel container) {// container.setLayout(gbl); // Add components to container and gbl // Force the layout of components before calling getLayoutWeights() // otherwise the result of getLayoutWeights() is not valid gbl.layoutContainer(container); // Set weights of all columns and rows to 1 double[][] weights = gbl.getLayoutWeights(); for (int i=0; i<2; i++) { for (int j=0; j<weights[i].length; j++) { weights[i][j] = 1; } } gbl.columnWeights = weights[0]; //gbl.rowWeights = weights[1]; } private static JTextField field = new JTextField(); public static void insertEmptyRows(int count, int width, int y, JPanel parent) { for (int i=0; i < count; i++) { Box.Filler filler = new Box.Filler(field.getMinimumSize(), field.getPreferredSize(), field.getMaximumSize()); parent.add(filler, new GridBagConstraints(0, y+i, width, 1, 0.0, 0.0, GridBagConstraints.SOUTHEAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -