Swing Cannot see Horizontal scroll bar

210 views Asked by At

I want to have a horizontal scroll bar to view whats there in "Description" column.

When the data in 2nd column exceeds I want to have a horizontal scrollbar to appear. This is my code: =========Working Example===============

import java.awt.*;

import javax.swing.*;
import javax.swing.plaf.basic.BasicBorders.MarginBorder;
import javax.swing.plaf.metal.MetalBorders.TableHeaderBorder;
import javax.swing.table.*;
import javax.swing.border.*;

public class TableRowRenderingTip extends JPanel
{
    static Object[] columnNames = {"Allowed Commands", "Description"};
    private final static Dimension scrollPaneDimenssion = new Dimension(70, 200);
    public TableRowRenderingTip()
    {       
        Object[][] data =
        {
            {"One",  "Allow proxies to act as tunnels for Allow proxies to act as tunnels for Allow proxies to act as tunnels for"},
            {"Two",  "Allow proxies to act as tunnels for Allow proxies to act as tunnels for Allow proxies to act as tunnels for"},
            {"Three","Allow proxies to act as tunnels for Allow proxies to act as tunnels for Allow proxies to act as tunnels for" },
            {"Four", "Allow proxies to act as tunnels for Allow proxies to act as tunnels for Allow proxies to act as tunnels for"},

        };      
        DefaultTableModel model = new DefaultTableModel(data, columnNames);     
        add( createData(model) );
    }



    private static JComponent createData(final DefaultTableModel model) 
    {       
        JTable inLineTable = new JTable( model );

        inLineTable.setShowGrid(false);
        inLineTable.setShowVerticalLines(false);

        inLineTable.getColumn(columnNames[0]).setMaxWidth(130);
        inLineTable.getColumn(columnNames[0]).setMinWidth(130);
        inLineTable.getColumn(columnNames[0]).setResizable(false);
        inLineTable.getColumn(columnNames[1]).setMinWidth(270);
        inLineTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);

        JScrollPane scrollPane = new JScrollPane(inLineTable);
        scrollPane.setMinimumSize(scrollPaneDimenssion);
        scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        return scrollPane;

    }

    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                createAndShowGUI();
            }
        });
    }

    public static void createAndShowGUI()
    {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       
        frame.add( new TableRowRenderingTip() );
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

================================================== But scrollPane size is fixed: I want to see the data in the 2nd column using a HORIZONTAL SCROLL BAR Image of the current state of the table

0

There are 0 answers