如何查出JTable实际占用的width
我试了getPreferredWidth  getPreferredScrollableViewportSize getWidth  getVisibleRectangle()这些方法都不行,哪位大神有好方法?  多谢

解决方案 »

  1.   

    得保证JTable不是宽度自适应的。
      

  2.   

    1L的什么意思?
    我是把jtable放在一个jscrollpane中的。说详细点哈
      

  3.   


    // Create a table with 10 rows and 5 columns
    JTable table = new JTable(10, 5);// Make the table vertically scrollable
    JScrollPane scrollPane = new JScrollPane(table);
    By default, a table is created with auto resize enabled. This means that if the user changes the width of the table, the columns automatically expand or shrink so that all the columns are entirely visible. In this mode, there is no need for a horizontal scrollbar. In order to get horizontal scrolling, auto resize must be disabled. 
    COPY
    // Disable auto resizing to make the table horizontal scrollable
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);引自:http://www.exampledepot.com/egs/javax.swing.table/Hscroll.html解决了,可是现在出现了另一个奇怪的现象:我设置PreferredSize()后再getPreferredSize(),结果竟然不是我设置的那个了,为什么呢?