Java JTabel 怎么放入JPanel
Java图形界面,这问题真要把我搞死了。。救命!我把JTabel放到JPanel里面只显示一点点,我是想把JTabel放到JPanel然后把JPanel放到JTabbed...
Java 图形界面 ,这问题真要把我搞死了。。 救命!我把JTabel 放到JPanel里面只显示一点点,我是想把JTabel 放到JPanel 然后把JPanel放到JTabbedPane 再放到JFrame,我新手 其他高深代码我不懂啊!
展开
2013-08-22
展开全部
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class JFrameTest extends JFrame{
private JTable jtable;
private Vector<Vector<String>> rowData;
private Vector<String> columnName;
private JPanel jpanel;
private JScrollPane scrollPanel;
private JTabbedPane tabbedPanel;
public JFrameTest()
{
init();
setComponentListener();
}
private void init()
{
this.setSize(300,300);
Container content=this.getContentPane();
jtable=new JTable(initRowData(),initColumnName());
scrollPanel=new JScrollPane(jtable,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jpanel=new JPanel();
jpanel.add(scrollPanel);
JPanel jpanel2=new JPanel();
jpanel2.add(new JLabel("JLabel"));
tabbedPanel=new JTabbedPane(JTabbedPane.LEFT );
tabbedPanel.addTab("这个JTable", scrollPanel);
tabbedPanel.addTab("这孙丛宽个JLabel", null, jpanel2,"jlabel2");
content.add(tabbedPanel);
}
private void setComponentListener()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private Vector<Vector<String>> initRowData()
{
rowData=new Vector<Vector<String>>();
Vector<String> columnData=new Vector<String>();
columnData.add("1");
columnData.add("郑丛2");
columnData.add("3");
rowData.add(columnData);
return rowData;
}
private Vector<String> initColumnName()
{
columnName=new Vector<String>();
columnName.add("test1");
columnName.add("test2");
columnName.add("test3"则亮);
return columnName;
}
public static void main(String[] args) {
new JFrameTest().setVisible(true); }}
import java.awt.*;
import java.util.*;
public class JFrameTest extends JFrame{
private JTable jtable;
private Vector<Vector<String>> rowData;
private Vector<String> columnName;
private JPanel jpanel;
private JScrollPane scrollPanel;
private JTabbedPane tabbedPanel;
public JFrameTest()
{
init();
setComponentListener();
}
private void init()
{
this.setSize(300,300);
Container content=this.getContentPane();
jtable=new JTable(initRowData(),initColumnName());
scrollPanel=new JScrollPane(jtable,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jpanel=new JPanel();
jpanel.add(scrollPanel);
JPanel jpanel2=new JPanel();
jpanel2.add(new JLabel("JLabel"));
tabbedPanel=new JTabbedPane(JTabbedPane.LEFT );
tabbedPanel.addTab("这个JTable", scrollPanel);
tabbedPanel.addTab("这孙丛宽个JLabel", null, jpanel2,"jlabel2");
content.add(tabbedPanel);
}
private void setComponentListener()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private Vector<Vector<String>> initRowData()
{
rowData=new Vector<Vector<String>>();
Vector<String> columnData=new Vector<String>();
columnData.add("1");
columnData.add("郑丛2");
columnData.add("3");
rowData.add(columnData);
return rowData;
}
private Vector<String> initColumnName()
{
columnName=new Vector<String>();
columnName.add("test1");
columnName.add("test2");
columnName.add("test3"则亮);
return columnName;
}
public static void main(String[] args) {
new JFrameTest().setVisible(true); }}
2013-08-22
展开全部
import java.util.Vector;import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;public class TestView extends JFrame {
private final Object [] colName = {"col1"空正, "col2", "col3"};
private final JTable tblData = new JTable();
private final JTabbedPane tbpExam = new JTabbedPane();
public TestView() {
initControl();
this.pack();
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private void initControl() {
final JScrollPane scpTable = new JScrollPane();
Object [][] data = {{"00","01","02"},{"10","斗贺悔11","12"},{"20","21","22"}};
initTable(data);
scpTable.getViewport().add(tblData, null);
tbpExam.addTab("Table"拍段, null, scpTable);
this.add(tbpExam);
}
private void initTable(Object [][] data) {
DefaultTableModel model = null;
if (data == null) {
model = new DefaultTableModel(colName, 0);
} else {
model = new DefaultTableModel(data, colName);
}
tblData.setModel(model);
}
public static void main (String[] args) {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
new TestView().setVisible(true);
}
});
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;public class TestView extends JFrame {
private final Object [] colName = {"col1"空正, "col2", "col3"};
private final JTable tblData = new JTable();
private final JTabbedPane tbpExam = new JTabbedPane();
public TestView() {
initControl();
this.pack();
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private void initControl() {
final JScrollPane scpTable = new JScrollPane();
Object [][] data = {{"00","01","02"},{"10","斗贺悔11","12"},{"20","21","22"}};
initTable(data);
scpTable.getViewport().add(tblData, null);
tbpExam.addTab("Table"拍段, null, scpTable);
this.add(tbpExam);
}
private void initTable(Object [][] data) {
DefaultTableModel model = null;
if (data == null) {
model = new DefaultTableModel(colName, 0);
} else {
model = new DefaultTableModel(data, colName);
}
tblData.setModel(model);
}
public static void main (String[] args) {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
new TestView().setVisible(true);
}
});
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-22
展开全部
1:JPanel 里面放入 JScrollPane2:嫌型JScrollPane里面放入jTable jTable就可以全稿谈部键者碰显示了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-22
展开全部
class Mypanel extends JPanel{
private JTable mytable = null;
JPanel p=new JPanel();
private JButton bu1 = null;
private JScrollPane sp = null;public Mypanel() {
setLayout(new BorderLayout());bu1 = new JButton("哗吵亩保存");sp=new JScrollPane();
String[] names={"333","222"};
String[][] date={{"乱森111","xxx"},{"111","xxx"碰旦}};
mytable=new JTable(date,names);
sp.add(mytable);
sp.setViewportView(mytable);
add(bu1,BorderLayout.SOUTH);
add(sp,BorderLayout.CENTER);
}
public static void main(String args[])
{
JFrame f=new JFrame();
f.setContentPane(new Mypanel());
f.setSize(330,300);
f.setVisible(true);
}
}
这个例子很简单,你应该能看懂
private JTable mytable = null;
JPanel p=new JPanel();
private JButton bu1 = null;
private JScrollPane sp = null;public Mypanel() {
setLayout(new BorderLayout());bu1 = new JButton("哗吵亩保存");sp=new JScrollPane();
String[] names={"333","222"};
String[][] date={{"乱森111","xxx"},{"111","xxx"碰旦}};
mytable=new JTable(date,names);
sp.add(mytable);
sp.setViewportView(mytable);
add(bu1,BorderLayout.SOUTH);
add(sp,BorderLayout.CENTER);
}
public static void main(String args[])
{
JFrame f=new JFrame();
f.setContentPane(new Mypanel());
f.setSize(330,300);
f.setVisible(true);
}
}
这个例子很简单,你应该能看懂
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询