本文主要是介绍Jtable加入jpanel,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
代码一:
package bt;import java.awt.*;
import java.awt.event.*;
import java.util.EventObject;
import javax.swing.*;
import javax.swing.table.*;public class bt1 {private JFrame frame;private JTable CompTable = null;private PanelTableModel CompModel = null;private JButton addButton = null;public static void main(String args[]) {try {UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());} catch (Exception fail) {}SwingUtilities.invokeLater(new Runnable() {@Overridepublic void run() {new bt1().makeUI();}});}public void makeUI() {CompTable = CreateCompTable();JScrollPane CompTableScrollpane = new JScrollPane(CompTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);JPanel bottomPanel = CreateBottomPanel();frame = new JFrame("Comp Table Test");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.add(CompTableScrollpane, BorderLayout.CENTER);frame.add(bottomPanel, BorderLayout.SOUTH);frame.setPreferredSize(new Dimension(800, 400));frame.setLocation(150, 150);frame.pack();frame.setVisible(true);}public JTable CreateCompTable() {CompModel = new PanelTableModel();CompModel.addRow();JTable table = new JTable(CompModel);table.setRowHeight(new CompCellPanel().getPreferredSize().height);table.setTableHeader(null);PanelCellEditorRenderer PanelCellEditorRenderer = new PanelCellEditorRenderer();table.setDefaultRenderer(Object.class, Panel
这篇关于Jtable加入jpanel的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!