List of usage examples for javax.swing JScrollPane setCorner
public void setCorner(String key, Component corner)
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 2s .com 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);/*from ww w.j a v a2s . 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);/*from w ww.java 2 s . co m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JTable table = new JTable(22, 5); table.setPreferredScrollableViewportSize(new Dimension(400, 300)); final JScrollPane scrollPane = new JScrollPane(table); JButton cornerButton = new JButton("#"); scrollPane.setCorner(JScrollPane.UPPER_TRAILING_CORNER, cornerButton); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); JFrame frame = new JFrame(); frame.add(scrollPane);//from w ww . jav a 2 s. c om frame.pack(); frame.setVisible(true); }
From source file:JScrollPaneHeadersandCorners.java
public static void main(String args[]) { final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" }, };//from w w w . j a v a 2 s. c om final Object headers[] = { "English", "#" }; JFrame frame = new JFrame("Table Printing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, new JButton("...")); frame.setSize(300, 150); 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; }/*ww w. jav a 2s . c o m*/ 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:FrozenColumnHeader.java
public void addNotify() { TableColumn column;//from www . j a v a 2 s .c o m super.addNotify(); TableColumnModel mainModel = mainTable.getColumnModel(); TableColumnModel headerModel = new DefaultTableColumnModel(); int frozenWidth = 0; for (int i = 0; i < columnCount; i++) { column = mainModel.getColumn(0); mainModel.removeColumn(column); headerModel.addColumn(column); frozenWidth += column.getPreferredWidth() + headerModel.getColumnMargin(); } headerTable.setColumnModel(headerModel); Component columnHeader = getColumnHeader().getView(); getColumnHeader().setView(null); JScrollPane mainScrollPane = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, mainTable); mainScrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, new JLabel("...")); headerTable.setPreferredScrollableViewportSize(new Dimension(frozenWidth, 0)); }
From source file:MainClass.java
public MainClass() { super("Row Header Test"); setSize(300, 200);//from w w w . j a v a2s . com setDefaultCloseOperation(EXIT_ON_CLOSE); TableModel tm = new AbstractTableModel() { String data[] = { "", "a", "b", "c", "d", "e" }; String headers[] = { "Row #", "Column 1", "Column 2", "Column 3", "Column 4", "Column 5" }; public int getColumnCount() { return data.length; } public int getRowCount() { return 1000; } public String getColumnName(int col) { return headers[col]; } public Object getValueAt(int row, int col) { return data[col] + row; } }; TableColumnModel cm = new DefaultTableColumnModel() { boolean first = true; public void addColumn(TableColumn tc) { if (first) { first = false; return; } tc.setMinWidth(150); super.addColumn(tc); } }; TableColumnModel rowHeaderModel = new DefaultTableColumnModel() { boolean first = true; public void addColumn(TableColumn tc) { if (first) { tc.setMaxWidth(tc.getPreferredWidth()); super.addColumn(tc); first = false; } } }; JTable jt = new JTable(tm, cm); JTable headerColumn = new JTable(tm, rowHeaderModel); jt.createDefaultColumnsFromModel(); headerColumn.createDefaultColumnsFromModel(); jt.setSelectionModel(headerColumn.getSelectionModel()); headerColumn.setBackground(Color.lightGray); headerColumn.setColumnSelectionAllowed(false); headerColumn.setCellSelectionEnabled(false); JViewport jv = new JViewport(); jv.setView(headerColumn); jv.setPreferredSize(headerColumn.getMaximumSize()); jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); JScrollPane jsp = new JScrollPane(jt); jsp.setRowHeader(jv); jsp.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, headerColumn.getTableHeader()); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:RowHeaderTable.java
public RowHeaderTable() { super("Row Header Test"); setSize(300, 200);/*ww w.ja va2s.co m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); TableModel tm = new AbstractTableModel() { String data[] = { "", "a", "b", "c", "d", "e" }; String headers[] = { "Row #", "Column 1", "Column 2", "Column 3", "Column 4", "Column 5" }; public int getColumnCount() { return data.length; } public int getRowCount() { return 1000; } public String getColumnName(int col) { return headers[col]; } // Synthesize some entries using the data values & the row # public Object getValueAt(int row, int col) { return data[col] + row; } }; // Create a column model for the main table. This model ignores the // first // column added, and sets a minimum width of 150 pixels for all others. TableColumnModel cm = new DefaultTableColumnModel() { boolean first = true; public void addColumn(TableColumn tc) { // Drop the first column . . . that'll be the row header if (first) { first = false; return; } tc.setMinWidth(150); // just for looks, really... super.addColumn(tc); } }; // Create a column model that will serve as our row header table. This // model picks a maximum width and only stores the first column. TableColumnModel rowHeaderModel = new DefaultTableColumnModel() { boolean first = true; public void addColumn(TableColumn tc) { if (first) { tc.setMaxWidth(tc.getPreferredWidth()); super.addColumn(tc); first = false; } // Drop the rest of the columns . . . this is the header column // only } }; JTable jt = new JTable(tm, cm); // Set up the header column and get it hooked up to everything JTable headerColumn = new JTable(tm, rowHeaderModel); jt.createDefaultColumnsFromModel(); headerColumn.createDefaultColumnsFromModel(); // Make sure that selections between the main table and the header stay // in sync (by sharing the same model) jt.setSelectionModel(headerColumn.getSelectionModel()); // Make the header column look pretty //headerColumn.setBorder(BorderFactory.createEtchedBorder()); headerColumn.setBackground(Color.lightGray); headerColumn.setColumnSelectionAllowed(false); headerColumn.setCellSelectionEnabled(false); // Put it in a viewport that we can control a bit JViewport jv = new JViewport(); jv.setView(headerColumn); jv.setPreferredSize(headerColumn.getMaximumSize()); // With out shutting off autoResizeMode, our tables won't scroll // correctly (horizontally, anyway) jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // We have to manually attach the row headers, but after that, the // scroll // pane keeps them in sync JScrollPane jsp = new JScrollPane(jt); jsp.setRowHeader(jv); jsp.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, headerColumn.getTableHeader()); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:MainClass.java
public static JScrollPane createPagingScrollPaneForTable(JTable jt) { JScrollPane jsp = new JScrollPane(jt); TableModel tmodel = jt.getModel(); if (!(tmodel instanceof PagingModel)) { return jsp; }/* w w w . j a v a 2s . c o m*/ final PagingModel model = (PagingModel) tmodel; final JButton upButton = new JButton("UP"); upButton.setEnabled(false); final JButton downButton = new JButton("DOWN"); if (model.getPageCount() <= 1) { downButton.setEnabled(false); } upButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.pageUp(); if (model.getPageOffset() == 0) { upButton.setEnabled(false); } downButton.setEnabled(true); } }); downButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.pageDown(); if (model.getPageOffset() == (model.getPageCount() - 1)) { downButton.setEnabled(false); } upButton.setEnabled(true); } }); jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); jsp.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, upButton); jsp.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, downButton); return jsp; }