problem with Jtable column headings length(code given)


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: problem with Jtable column headings length(code given)

  1. #1
    Satish Guest

    problem with Jtable column headings length(code given)


    Hi,


    I am having a JTable with 6 column headings. I am creating a table model
    with these headings and data. I am adding this table to a Jscrollpane. Everything
    is fine. I get the data and columns displayed on the ecreen. but, the problem
    is the length of all the columns is less than the Jscrollpane and when the
    table is displayed the width of all the columns is not reaching the entire
    width of the Jscrollpane and I find a gap between the two, which looks very
    ackward. I made setResizeMode to be true as in the code below

    inportedTable = new JTable(((SubscriberReassignmentModel)model).getInportedTableModelSC0());
    addSelectionListener(inportedTable);
    outportedTable = new JTable(((SubscriberReassignmentModel)model).getOutportedTableModelSC0());
    addSelectionListener(outportedTable);
    inportedTable.getTableHeader().setReorderingAllowed(false);
    outportedTable.getTableHeader().setReorderingAllowed(false);
    inportedTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    outportedTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    inportedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    outportedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    // scrollpane and set scrollpane properties
    spInportedTable = new JScrollPane(inportedTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    spInportedTable.getViewport().putClientProperty("EnableWindowBlit",
    Boolean.TRUE);
    spOutportedTable = new JScrollPane(outportedTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    spOutportedTable.getViewport().putClientProperty("EnableWindowBlit",
    Boolean.TRUE);
    spInportedTable.setPreferredSize(new Dimension(950, 450));
    spOutportedTable.setPreferredSize(new Dimension(950, 450));


    the code for clumns is shown below


    private final String[] outportedHeaders = { // Table headers
    tablelblobj.getString("LowerLimit "),
    tablelblobj.getString("UpperLimit "),
    tablelblobj.getString("DestinationIP(A) "),
    tablelblobj.getString("DestinationIP(B) "),
    tablelblobj.getString("NodeID "),
    tablelblobj.getString("Mode "),

    };
    private final String[] inportedHeaders = { // Table headers
    tablelblobj.getString("LowerLimit "),
    tablelblobj.getString("UpperLimit "),
    tablelblobj.getString("OriginationIP(A) "),
    tablelblobj.getString("OriginationIP(B) "),
    tablelblobj.getString("NodeID "),
    tablelblobj.getString("Mode "),

    };


    private SubscriberReassignmentTableModel inportedTableModelSC0 = null;
    private SubscriberReassignmentTableModel inportedTableModelSC1 = null;
    private SubscriberReassignmentTableModel outportedTableModelSC0 = null;
    private SubscriberReassignmentTableModel outportedTableModelSC1 = null;
    Object[] [] outportedDataSC0;
    Object[] [] outportedDataSC1;
    Object[] [] inportedDataSC0;
    Object[] [] inportedDataSC1;
    private Object[] [] inportedErrorList = null;
    private Object[] [] outportedErrorList = null;
    Please help me if anyone understiid the problem and there is a solution to
    it ?





    Regards



    Satish



  2. #2
    Paul Clapham Guest

    Re: problem with Jtable column headings length(code given)

    If you want to alter the width of a column in a JTable, try something like
    this:

    thetable.getColumnModel().getColumn(1).setMinWidth(300);

    (or setPreferredWidth, setMaxWidth).

    PC2




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center