Example usage for javax.swing JScrollPane setRowHeaderView

List of usage examples for javax.swing JScrollPane setRowHeaderView

Introduction

In this page you can find the example usage for javax.swing JScrollPane setRowHeaderView.

Prototype

public void setRowHeaderView(Component view) 

Source Link

Document

Creates a row-header viewport if necessary, sets its view and then adds the row-header viewport to the scrollpane.

Usage

From source file:CornerSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Cornering Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Icon miniLogo = new ImageIcon("logo.gif");
    Icon acrossLogo = new ImageIcon("logo-across.jpg");
    Icon downLogo = new ImageIcon("logo-down.jpg");
    Icon bookCover = new ImageIcon("puzzlebook.jpg");
    JLabel logoLabel = new JLabel(miniLogo);
    JLabel columnLabel = new JLabel(acrossLogo);
    JLabel rowLabel = new JLabel(downLogo);
    JLabel coverLabel = new JLabel(bookCover);
    JScrollPane scrollPane = new JScrollPane(coverLabel);
    scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, logoLabel);
    scrollPane.setColumnHeaderView(columnLabel);
    scrollPane.setRowHeaderView(rowLabel);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 200);/*from  w w w. j av a  2 s.co  m*/
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(final String args[]) {
    final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } };
    final Object headers[] = { "English", "Digit" };

    JFrame frame = new JFrame("Scrollless Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTable table = new JTable(rows, headers);

    JScrollPane scrollPane = new JScrollPane(table);
    JViewport viewport = new JViewport();
    viewport.setView(table);/* w  w w . j  a  v  a  2  s.c  o  m*/
    scrollPane.setColumnHeaderView(new JLabel("table header here"));
    scrollPane.setRowHeaderView(viewport);

    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("Cornering Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button = new JButton("+");

    JLabel bigLabel = new JLabel("A");
    bigLabel.setPreferredSize(new Dimension(400, 400));
    bigLabel.setBorder(new LineBorder(Color.red));

    JScrollPane scrollPane = new JScrollPane(bigLabel);
    scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, button);
    scrollPane.setColumnHeaderView(new JLabel("B"));
    scrollPane.setRowHeaderView(new JLabel("C"));

    ActionListener actionListener = new JScrollPaneToTopAction(scrollPane);
    button.addActionListener(actionListener);

    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 200);/* ww w.j  a va  2s .c  o m*/
    frame.setVisible(true);
}

From source file:ButtonCornerSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Cornering Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Icon acrossLogo = new ImageIcon("logo-across.jpg");
    Icon downLogo = new ImageIcon("logo-down.jpg");
    Icon bookCover = new ImageIcon("puzzlebook.jpg");
    JLabel columnLabel = new JLabel(acrossLogo);
    JLabel rowLabel = new JLabel(downLogo);
    JLabel coverLabel = new JLabel(bookCover);
    JButton button = new JButton("+");
    button.setFont(new Font("Monospaced", Font.PLAIN, 8));
    JScrollPane scrollPane = new JScrollPane(coverLabel);
    scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, button);
    scrollPane.setColumnHeaderView(columnLabel);
    scrollPane.setRowHeaderView(rowLabel);

    ActionListener actionListener = new JScrollPaneToTopAction(scrollPane);
    button.addActionListener(actionListener);

    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 200);/*  w  ww.j a v  a  2s. c om*/
    frame.setVisible(true);
}

From source file:FixedColumnModel.java

public static void main(String args[]) {

    final Object rowData[][] = { { "1", "one", "I" }, { "2", "two", "II" }, { "3", "three", "III" } };

    final String columnNames[] = { "#", "English", "Roman" };

    final TableModel fixedColumnModel = new AbstractTableModel() {
        public int getColumnCount() {
            return 1;
        }//from   w  w  w  . ja va2  s. c  om

        public String getColumnName(int column) {
            return columnNames[column];
        }

        public int getRowCount() {
            return rowData.length;
        }

        public Object getValueAt(int row, int column) {
            return rowData[row][column];
        }
    };

    final TableModel mainModel = new AbstractTableModel() {
        public int getColumnCount() {
            return columnNames.length - 1;
        }

        public String getColumnName(int column) {
            return columnNames[column + 1];
        }

        public int getRowCount() {
            return rowData.length;
        }

        public Object getValueAt(int row, int column) {
            return rowData[row][column + 1];
        }
    };

    JTable fixedTable = new JTable(fixedColumnModel);
    fixedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    JTable mainTable = new JTable(mainModel);
    mainTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    ListSelectionModel model = fixedTable.getSelectionModel();
    mainTable.setSelectionModel(model);

    JScrollPane scrollPane = new JScrollPane(mainTable);
    Dimension fixedSize = fixedTable.getPreferredSize();
    JViewport viewport = new JViewport();
    viewport.setView(fixedTable);
    viewport.setPreferredSize(fixedSize);
    viewport.setMaximumSize(fixedSize);
    scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, fixedTable.getTableHeader());
    scrollPane.setRowHeaderView(viewport);

    JFrame frame = new JFrame("Fixed Column Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo6.java

/**
 * reset dataTable to default (demo data), and refesh chart
 *//*  w ww  . ja va  2  s .  co m*/
public void resetExample() {
    isDemo = true;
    IntervalXYDataset dataset = createDataset(isDemo);

    JFreeChart chart = createChart(dataset);
    chartPanel = new ChartPanel(chart, false);
    setChart();

    hasExample = true;

    //convertor.dataset2Table(dataset);   
    convertor.data2Table(raw_x, y_freq, domainLabel, rangeLabel, data_count);
    JTable tempDataTable = convertor.getTable();
    resetTableRows(tempDataTable.getRowCount() + 1);

    columnModel = dataTable.getColumnModel();
    dataTable.setTableHeader(new EditableHeader(columnModel));

    resetTableColumns(tempDataTable.getColumnCount());
    for (int i = 0; i < tempDataTable.getColumnCount(); i++) {
        columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i));
        //  System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i));
    }

    for (int i = 0; i < tempDataTable.getRowCount(); i++)
        for (int j = 0; j < tempDataTable.getColumnCount(); j++) {
            dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j);
        }
    columnModel = dataTable.getColumnModel();
    dataTable.setTableHeader(new EditableHeader(columnModel));

    dataPanel.removeAll();
    JScrollPane tablePanel = new JScrollPane(dataTable);
    tablePanel.setRowHeaderView(headerTable);
    dataPanel.add(tablePanel);
    dataPanel.add(new JScrollPane(summaryPanel));
    dataTable.setGridColor(Color.gray);
    dataTable.setShowGrid(true);
    // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003
    try {
        dataTable.setDragEnabled(true);
    } catch (Exception e) {
    }

    dataPanel.validate();

    setMapping();

    updateStatus(url);
}

From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo7.java

public void resetExample() {
    isDemo = true;/*from   w w w. j a  v  a 2s  .  c  o m*/
    dataset = createDataset(isDemo);

    JFreeChart chart = createChart(dataset);
    chartPanel = new ChartPanel(chart, false);
    setChart();

    hasExample = true;

    //convertor.dataset2Table(dataset);   
    convertor.data2Table(raw_x, raw_y, domainLabel, rangeLabel, xyLength);

    JTable tempDataTable = convertor.getTable();
    resetTableRows(tempDataTable.getRowCount() + 1);

    columnModel = dataTable.getColumnModel();
    dataTable.setTableHeader(new EditableHeader(columnModel));

    resetTableColumns(tempDataTable.getColumnCount());
    for (int i = 0; i < tempDataTable.getColumnCount(); i++) {
        columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i));
        //  System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i));
    }

    for (int i = 0; i < tempDataTable.getRowCount(); i++)
        for (int j = 0; j < tempDataTable.getColumnCount(); j++) {
            dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j);
        }

    columnModel = dataTable.getColumnModel();
    dataTable.setTableHeader(new EditableHeader(columnModel));

    dataPanel.removeAll();
    JScrollPane tablePanel = new JScrollPane(dataTable);
    tablePanel.setRowHeaderView(headerTable);
    dataPanel.add(tablePanel);
    dataPanel.add(new JScrollPane(summaryPanel));
    dataTable.setGridColor(Color.gray);
    dataTable.setShowGrid(true);
    // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003
    try {
        dataTable.setDragEnabled(true);
    } catch (Exception e) {
    }

    dataPanel.validate();

    setMapping();

    updateStatus(url);
}

From source file:components.ScrollDemo.java

public ScrollDemo() {
    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

    //Get the image to use.
    ImageIcon bee = createImageIcon("images/flyingBee.jpg");

    //Create the row and column headers.
    columnView = new Rule(Rule.HORIZONTAL, true);
    rowView = new Rule(Rule.VERTICAL, true);

    if (bee != null) {
        columnView.setPreferredWidth(bee.getIconWidth());
        rowView.setPreferredHeight(bee.getIconHeight());
    } else {/*from ww  w  .  java2  s .c  om*/
        columnView.setPreferredWidth(320);
        rowView.setPreferredHeight(480);
    }

    //Create the corners.
    JPanel buttonCorner = new JPanel(); //use FlowLayout
    isMetric = new JToggleButton("cm", true);
    isMetric.setFont(new Font("SansSerif", Font.PLAIN, 11));
    isMetric.setMargin(new Insets(2, 2, 2, 2));
    isMetric.addItemListener(this);
    buttonCorner.add(isMetric);

    //Set up the scroll pane.
    picture = new ScrollablePicture(bee, columnView.getIncrement());
    JScrollPane pictureScrollPane = new JScrollPane(picture);
    pictureScrollPane.setPreferredSize(new Dimension(300, 250));
    pictureScrollPane.setViewportBorder(BorderFactory.createLineBorder(Color.black));

    pictureScrollPane.setColumnHeaderView(columnView);
    pictureScrollPane.setRowHeaderView(rowView);

    //Set the corners.
    //In theory, to support internationalization you would change
    //UPPER_LEFT_CORNER to UPPER_LEADING_CORNER,
    //LOWER_LEFT_CORNER to LOWER_LEADING_CORNER, and
    //UPPER_RIGHT_CORNER to UPPER_TRAILING_CORNER.  In practice,
    //bug #4467063 makes that impossible (in 1.4, at least).
    pictureScrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, buttonCorner);
    pictureScrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, new Corner());
    pictureScrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, new Corner());

    //Put it in this panel.
    add(pictureScrollPane);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:misc.AccessibleScrollDemo.java

public AccessibleScrollDemo() {
    // Get the image to use.
    ImageIcon bee = createImageIcon("images/flyingBee.jpg", "Photograph of a flying bee.");

    // Create the row and column headers.
    columnView = new Rule(Rule.HORIZONTAL, true);
    if (bee != null) {
        columnView.setPreferredWidth(bee.getIconWidth());
    } else {/*  w ww  . j a  v  a2  s.com*/
        columnView.setPreferredWidth(320);
    }
    columnView.getAccessibleContext().setAccessibleName("Column Header");
    columnView.getAccessibleContext()
            .setAccessibleDescription("Displays horizontal ruler for " + "measuring scroll pane client.");
    rowView = new Rule(Rule.VERTICAL, true);
    if (bee != null) {
        rowView.setPreferredHeight(bee.getIconHeight());
    } else {
        rowView.setPreferredHeight(480);
    }
    rowView.getAccessibleContext().setAccessibleName("Row Header");
    rowView.getAccessibleContext()
            .setAccessibleDescription("Displays vertical ruler for " + "measuring scroll pane client.");

    // Create the corners.
    JPanel buttonCorner = new JPanel();
    isMetric = new JToggleButton("cm", true);
    isMetric.setFont(new Font("SansSerif", Font.PLAIN, 11));
    isMetric.setMargin(new Insets(2, 2, 2, 2));
    isMetric.addItemListener(this);
    isMetric.setToolTipText("Toggles rulers' unit of measure " + "between inches and centimeters.");
    buttonCorner.add(isMetric); //Use the default FlowLayout
    buttonCorner.getAccessibleContext().setAccessibleName("Upper Left Corner");

    String desc = "Fills the corner of a scroll pane " + "with color for aesthetic reasons.";
    Corner lowerLeft = new Corner();
    lowerLeft.getAccessibleContext().setAccessibleName("Lower Left Corner");
    lowerLeft.getAccessibleContext().setAccessibleDescription(desc);

    Corner upperRight = new Corner();
    upperRight.getAccessibleContext().setAccessibleName("Upper Right Corner");
    upperRight.getAccessibleContext().setAccessibleDescription(desc);

    // Set up the scroll pane.
    picture = new ScrollablePicture(bee, columnView.getIncrement());
    picture.setToolTipText(bee.getDescription());
    picture.getAccessibleContext().setAccessibleName("Scroll pane client");

    JScrollPane pictureScrollPane = new JScrollPane(picture);
    pictureScrollPane.setPreferredSize(new Dimension(300, 250));
    pictureScrollPane.setViewportBorder(BorderFactory.createLineBorder(Color.black));

    pictureScrollPane.setColumnHeaderView(columnView);
    pictureScrollPane.setRowHeaderView(rowView);

    // In theory, to support internationalization you would change
    // UPPER_LEFT_CORNER to UPPER_LEADING_CORNER,
    // LOWER_LEFT_CORNER to LOWER_LEADING_CORNER, and
    // UPPER_RIGHT_CORNER to UPPER_TRAILING_CORNER.  In practice,
    // bug #4467063 makes that impossible (at least in 1.4.0).
    pictureScrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, buttonCorner);
    pictureScrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, lowerLeft);
    pictureScrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, upperRight);

    // Put it in this panel.
    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    add(pictureScrollPane);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:jmap2gml.ScriptGui.java

/**
 * Formats the window, initializes the JMap2Script object, and sets up all
 * the necessary events.// ww w . j  a v  a  2  s  .c o  m
 */
public ScriptGui() {
    setTitle("jmap to gml script converter");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    getContentPane().setLayout(new GridBagLayout());

    this.addWindowListener(new WindowListener() {
        @Override
        public void windowOpened(WindowEvent we) {
        }

        @Override
        public void windowClosing(WindowEvent we) {
            saveConfig();
        }

        @Override
        public void windowClosed(WindowEvent we) {
        }

        @Override
        public void windowIconified(WindowEvent we) {
        }

        @Override
        public void windowDeiconified(WindowEvent we) {
        }

        @Override
        public void windowActivated(WindowEvent we) {
        }

        @Override
        public void windowDeactivated(WindowEvent we) {
        }
    });

    GridBagConstraints c = new GridBagConstraints();

    setResizable(true);
    setIconImage((new ImageIcon("spikeup.png")).getImage());

    jta = new JTextArea(38, 30);

    loadConfig();

    JScrollPane jsp = new JScrollPane(jta);
    jsp.setRowHeaderView(new TextLineNumber(jta));
    jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    jsp.setSize(jsp.getWidth(), 608);

    // menu bar
    JMenuBar menubar = new JMenuBar();

    // file menu
    JMenu file = new JMenu("File");

    // load button
    JMenuItem load = new JMenuItem("Load jmap");
    load.addActionListener(ae -> {
        JFileChooser fileChooser = new JFileChooser(prevDirectory);
        fileChooser.setFileFilter(new FileNameExtensionFilter("jmap file", "jmap", "jmap"));

        int returnValue = fileChooser.showOpenDialog(null);

        if (returnValue == JFileChooser.APPROVE_OPTION) {
            File selectedFile = fileChooser.getSelectedFile();

            prevDirectory = selectedFile.getAbsolutePath();

            jm2s = new ScriptFromJmap(selectedFile.getPath(), false);

            jta.setText("");
            jta.append(jm2s.toString());
            jta.setCaretPosition(0);

            writeFile.setEnabled(true);

            drawPanel.setItems(jta.getText().split("\n"));
        }
    });

    // add load to file menu
    file.add(load);

    // button to save script to file
    writeFile = new JMenuItem("Write file");
    writeFile.addActionListener(ae -> {
        if (jm2s != null) {
            PrintWriter out;
            try {
                File f = new File(
                        jm2s.getFileName().substring(0, jm2s.getFileName().lastIndexOf(".jmap")) + ".gml");
                out = new PrintWriter(f);
                out.append(jm2s.toString());
                out.close();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    writeFile.setEnabled(false);

    JMenuItem gmx = new JMenuItem("Export as gmx");
    gmx.addActionListener(ae -> {
        String fn = String.format("%s.room.gmx", prevDirectory);

        JFileChooser fc = new JFileChooser(prevDirectory);
        fc.setSelectedFile(new File(fn));
        fc.setFileFilter(new FileNameExtensionFilter("Game Maker XML", "gmx", "gmx"));
        fc.showDialog(null, "Save");
        File f = fc.getSelectedFile();

        if (f != null) {
            try {
                GMX.itemsToGMX(drawPanel.items, new FileOutputStream(f));
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });

    // add to file menu
    file.add(writeFile);
    file.add(gmx);

    // add file menu to the menubar
    menubar.add(file);

    // Edit menu

    // display menu
    JMenu display = new JMenu("Display");

    JMenuItem update = new JMenuItem("Update");

    update.addActionListener(ae -> {
        drawPanel.setItems(jta.getText().split("\n"));
    });

    display.add(update);

    JMenuItem gridToggle = new JMenuItem("Toggle Grid");
    gridToggle.addActionListener(ae -> {
        drawPanel.toggleGrid();
    });
    display.add(gridToggle);

    JMenuItem gridOptions = new JMenuItem("Modify Grid");
    gridOptions.addActionListener(ae -> {
        drawPanel.modifyGrid();
    });
    display.add(gridOptions);

    menubar.add(display);

    // sets the menubar
    setJMenuBar(menubar);

    // add the text area to the window
    c.gridx = 0;
    c.gridy = 0;
    add(jsp, c);

    // initialize the preview panel
    drawPanel = new Preview(this);
    JScrollPane scrollPane = new JScrollPane(drawPanel);

    // add preview panel to the window
    c.gridx = 1;
    c.gridwidth = 2;
    add(scrollPane, c);

    pack();
    setMinimumSize(this.getSize());
    setLocationRelativeTo(null);
    setVisible(true);
    drawPanel.setItems(jta.getText().split("\n"));
}