2 a1by1 a1by1 于 2014.05.29 17:14 提问

JScrollPane 的水平滚动条不显示啦,急求大伙看下
DefaultTableModel model = new DefaultTableModel(datas, columns);

    JTable table = new CommonJTable(model);

    //表格大小
    table.setPreferredSize(new Dimension(1200, 800));



      //选中行颜色
    table.setSelectionBackground(Color.yellow);  
    //不拖动
    table.getTableHeader().setReorderingAllowed(false);

     DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();// 设置table内容居中  

           tcr.setHorizontalAlignment(SwingConstants.CENTER);// 
           table.setDefaultRenderer(Object.class, tcr);  

           FitTableColumns(table);



    JScrollPane upPane = new JScrollPane();

    upPane.setViewportView(table);
    upPane.setPreferredSize(new Dimension(800,700));

    upPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    upPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 
    upPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    table.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);// 水平滚动条
    JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, top, upPane);
     this.add(split);

1个回答

lzp_lrp
lzp_lrp   Ds   Rxr 2015.06.08 08:58


upPane.setPreferredSize(new Dimension(800,700));

前加一句
upPane.setSize(800, 700);

试试

Csdn user default icon
上传中...
上传图片
插入图片