Topic: 请教一个关于类加入的问题? |
Print this page |
1.请教一个关于类加入的问题? | Copy to clipboard |
Posted by: ccic134302 Posted on: 2003-03-05 09:03 我下载了一个关于表格界面的类,但不知如何加入我的程序界面里? 请各位大虾给指点指点,问题很菜,请多原谅!!! |
2.Re:请教一个关于类加入的问题? [Re: ccic134302] | Copy to clipboard |
Posted by: snowbug Posted on: 2003-03-06 01:14 Please be more specific before anyone can help you with this. |
3.Re:请教一个关于类加入的问题? [Re: ccic134302] | Copy to clipboard |
Posted by: MrTong Posted on: 2003-03-10 10:01 it is easy. import your table class then u can use it ,just like Vector u must import java.util.* |
4.Re:请教一个关于类加入的问题? [Re: ccic134302] | Copy to clipboard |
Posted by: ccic134302 Posted on: 2003-03-10 11:31 mrtong大哥,以下是代码,麻烦你给看看,怎么能加入我的程序里,并且加入我的界面里,非常感谢你的回复!!! /* (swing1.1beta3) */ //package jp.gr.java_conf.tame.swing.examples; package sjh; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; /** * @version 1.0 11/09/98 */ class RowHeaderRenderer extends JLabel implements ListCellRenderer { RowHeaderRenderer(JTable table) { JTableHeader header = table.getTableHeader(); setOpaque(true); setBorder(UIManager.getBorder("TableHeader.cellBorder")); setHorizontalAlignment(CENTER); setForeground(header.getForeground()); setBackground(header.getBackground()); setFont(header.getFont()); } public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setText((value == null) ? "" : value.toString()); return this; } } public class RowHeaderExample extends JFrame { public RowHeaderExample() { super( "Row Header Example" ); setSize( 800, 600 ); ListModel lm = new AbstractListModel() { String headers[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","aa","bb","cc","dd","ee","ff","gg","hh","ii","oo"}; public int getSize() { return headers.length; } public Object getElementAt(int index) { return headers[index]; } }; DefaultTableModel dm = new DefaultTableModel(lm.getSize(),10); JTable table = new JTable( dm ); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); JList rowHeader = new JList(lm); rowHeader.setFixedCellWidth(50); rowHeader.setFixedCellHeight(table.getRowHeight() + table.getRowMargin()); // + table.getIntercellSpacing().height); rowHeader.setCellRenderer(new RowHeaderRenderer(table)); JScrollPane scroll = new JScrollPane( table ); scroll.setRowHeaderView(rowHeader); getContentPane().add(scroll, BorderLayout.CENTER); } public static void main(String[] args) { RowHeaderExample frame = new RowHeaderExample(); frame.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit(0); } }); frame.setVisible(true); } } |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |