Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Swing无法看到水平滚动条_Java_Swing_Jtable_Jscrollpane_Jscrollbar - Fatal编程技术网

Java Swing无法看到水平滚动条

Java Swing无法看到水平滚动条,java,swing,jtable,jscrollpane,jscrollbar,Java,Swing,Jtable,Jscrollpane,Jscrollbar,我想有一个水平滚动条来查看“描述”列中的内容 当第二列中的数据超过时,我希望显示一个水平滚动条。这是我的代码: ==========工作示例=============== import java.awt.*; import javax.swing.*; import javax.swing.plaf.basic.BasicBorders.MarginBorder; import javax.swing.plaf.metal.MetalBorders.TableHeaderBorder; imp

我想有一个水平滚动条来查看“描述”列中的内容

当第二列中的数据超过时,我希望显示一个水平滚动条。这是我的代码: ==========工作示例===============

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);
    }
}
================================================== 但是
滚动窗格
大小是固定的: 我想使用水平滚动条查看第二列中的数据

尽管问题中使用了粗体大字体,但如果没有SSCCE/MCVE、简短、可运行、可编译、,使用本地变量中JTable的硬编码值,我在那里添加了一个工作示例,试图找到如何获取您必须使用的水平滚动条,以覆盖JScrollPane的get/setPreferredScrollableViewportSize,但是我很抱歉,我发布的代码生成了一些类似于这里发布的图片的东西。代码甚至没有显示垂直滚动条。为了生成图片中的图片,我需要一个框架。因此,我在一个小程序中进行了复制。不管怎样,我从感谢你的帮助中得到了答案:)