List of usage examples for javax.swing JScrollPane setPreferredSize
@BeanProperty(preferred = true, description = "The preferred size of the component.") public void setPreferredSize(Dimension preferredSize)
From source file:WindowEventDemo.java
public WindowEventDemo() { super(new BorderLayout()); display = new JTextArea(); display.setEditable(false);//from www . j a v a2 s .c om JScrollPane scrollPane = new JScrollPane(display); scrollPane.setPreferredSize(new Dimension(500, 450)); add(scrollPane, BorderLayout.CENTER); frame.addWindowListener(this); frame.addWindowFocusListener(this); frame.addWindowStateListener(this); checkWM(); }
From source file:events.ContainerEventDemo.java
public ContainerEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); //Initialize an empty list of buttons. buttonList = new Vector<JButton>(10, 10); //Create all the components. addButton = new JButton("Add a button"); addButton.setActionCommand(ADD);/* w w w . j a v a 2s .com*/ addButton.addActionListener(this); removeButton = new JButton("Remove a button"); removeButton.setActionCommand(REMOVE); removeButton.addActionListener(this); buttonPanel = new JPanel(new GridLayout(1, 1)); buttonPanel.setPreferredSize(new Dimension(200, 75)); buttonPanel.addContainerListener(this); display = new JTextArea(); display.setEditable(false); JScrollPane scrollPane = new JScrollPane(display); scrollPane.setPreferredSize(new Dimension(200, 75)); clearButton = new JButton("Clear text area"); clearButton.setActionCommand(CLEAR); clearButton.addActionListener(this); c.fill = GridBagConstraints.BOTH; //Fill entire cell. c.weighty = 1.0; //Button area and message area have equal height. c.gridwidth = GridBagConstraints.REMAINDER; //end of row gridbag.setConstraints(scrollPane, c); add(scrollPane); c.weighty = 0.0; gridbag.setConstraints(clearButton, c); add(clearButton); c.weightx = 1.0; //Add/remove buttons have equal width. c.gridwidth = 1; //NOT end of row gridbag.setConstraints(addButton, c); add(addButton); c.gridwidth = GridBagConstraints.REMAINDER; //end of row gridbag.setConstraints(removeButton, c); add(removeButton); c.weighty = 1.0; //Button area and message area have equal height. gridbag.setConstraints(buttonPanel, c); add(buttonPanel); setPreferredSize(new Dimension(400, 400)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:DocumentEventDemo.java
public DocumentEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); JButton button = new JButton("Clear"); button.addActionListener(this); textField = new JTextField(20); textField.addActionListener(new MyTextActionListener()); textField.getDocument().addDocumentListener(new MyDocumentListener()); textField.getDocument().putProperty("name", "Text Field"); textArea = new JTextArea(); textArea.getDocument().addDocumentListener(new MyDocumentListener()); textArea.getDocument().putProperty("name", "Text Area"); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setPreferredSize(new Dimension(200, 75)); displayArea = new JTextArea(); displayArea.setEditable(false);//from w ww .j av a 2s .com JScrollPane displayScrollPane = new JScrollPane(displayArea); displayScrollPane.setPreferredSize(new Dimension(200, 75)); c.gridx = 0; c.gridy = 0; c.weightx = 1.0; c.fill = GridBagConstraints.HORIZONTAL; gridbag.setConstraints(textField, c); add(textField); c.gridx = 0; c.gridy = 1; c.weightx = 0.0; c.gridheight = 2; c.fill = GridBagConstraints.BOTH; gridbag.setConstraints(scrollPane, c); add(scrollPane); c.gridx = 1; c.gridy = 0; c.weightx = 1.0; c.weighty = 1.0; gridbag.setConstraints(displayScrollPane, c); add(displayScrollPane); c.gridx = 1; c.gridy = 2; c.weightx = 0.0; c.gridheight = 1; c.weighty = 0.0; c.fill = GridBagConstraints.HORIZONTAL; gridbag.setConstraints(button, c); add(button); setPreferredSize(new Dimension(450, 250)); 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 w w . j a v a2 s . c o m*/ 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:gui.accessories.BattleSimFx.java
@Override public void init() { tableModel = new SampleTableModel(); // create javafx panel for charts chartFxPanel = new JFXPanel(); chartFxPanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, PANEL_HEIGHT_INT)); //JTable/* ww w.j a v a2 s .c om*/ JTable table = new JTable(tableModel); table.setAutoCreateRowSorter(true); table.setGridColor(Color.DARK_GRAY); BattleSimFx.DecimalFormatRenderer renderer = new BattleSimFx.DecimalFormatRenderer(); renderer.setHorizontalAlignment(JLabel.RIGHT); for (int i = 0; i < table.getColumnCount(); i++) { table.getColumnModel().getColumn(i).setCellRenderer(renderer); } JScrollPane tablePanel = new JScrollPane(table); tablePanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, TABLE_PANEL_HEIGHT_INT)); JPanel chartTablePanel = new JPanel(); chartTablePanel.setLayout(new BorderLayout()); //Split pane that holds both chart and table JSplitPane jsplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); jsplitPane.setTopComponent(chartTablePanel); jsplitPane.setBottomComponent(tablePanel); jsplitPane.setDividerLocation(410); chartTablePanel.add(chartFxPanel, BorderLayout.CENTER); // add(tablePanel, BorderLayout.CENTER); add(jsplitPane, BorderLayout.CENTER); // create JavaFX scene Platform.runLater(new Runnable() { @Override public void run() { createScene(); } }); }
From source file:ContainerEventDemo.java
public ContainerEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); // Initialize an empty list of buttons. buttonList = new Vector<JButton>(10, 10); // Create all the components. addButton = new JButton("Add a button"); addButton.setActionCommand(ADD);/*ww w. j a v a 2s. co m*/ addButton.addActionListener(this); removeButton = new JButton("Remove a button"); removeButton.setActionCommand(REMOVE); removeButton.addActionListener(this); buttonPanel = new JPanel(new GridLayout(1, 1)); buttonPanel.setPreferredSize(new Dimension(200, 75)); buttonPanel.addContainerListener(this); display = new JTextArea(); display.setEditable(false); JScrollPane scrollPane = new JScrollPane(display); scrollPane.setPreferredSize(new Dimension(200, 75)); clearButton = new JButton("Clear text area"); clearButton.setActionCommand(CLEAR); clearButton.addActionListener(this); c.fill = GridBagConstraints.BOTH; // Fill entire cell. c.weighty = 1.0; // Button area and message area have equal height. c.gridwidth = GridBagConstraints.REMAINDER; // end of row gridbag.setConstraints(scrollPane, c); add(scrollPane); c.weighty = 0.0; gridbag.setConstraints(clearButton, c); add(clearButton); c.weightx = 1.0; // Add/remove buttons have equal width. c.gridwidth = 1; // NOT end of row gridbag.setConstraints(addButton, c); add(addButton); c.gridwidth = GridBagConstraints.REMAINDER; // end of row gridbag.setConstraints(removeButton, c); add(removeButton); c.weighty = 1.0; // Button area and message area have equal height. gridbag.setConstraints(buttonPanel, c); add(buttonPanel); setPreferredSize(new Dimension(400, 400)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:Main.java
public Main() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); // Initialize an empty list of buttons. buttonList = new Vector<JButton>(10, 10); // Create all the components. addButton = new JButton("Add a button"); addButton.setActionCommand(ADD);//from w w w . j a v a 2 s . c om addButton.addActionListener(this); removeButton = new JButton("Remove a button"); removeButton.setActionCommand(REMOVE); removeButton.addActionListener(this); buttonPanel = new JPanel(new GridLayout(1, 1)); buttonPanel.setPreferredSize(new Dimension(200, 75)); buttonPanel.addContainerListener(this); display = new JTextArea(); display.setEditable(false); JScrollPane scrollPane = new JScrollPane(display); scrollPane.setPreferredSize(new Dimension(200, 75)); clearButton = new JButton("Clear text area"); clearButton.setActionCommand(CLEAR); clearButton.addActionListener(this); c.fill = GridBagConstraints.BOTH; // Fill entire cell. c.weighty = 1.0; // Button area and message area have equal height. c.gridwidth = GridBagConstraints.REMAINDER; // end of row gridbag.setConstraints(scrollPane, c); add(scrollPane); c.weighty = 0.0; gridbag.setConstraints(clearButton, c); add(clearButton); c.weightx = 1.0; // Add/remove buttons have equal width. c.gridwidth = 1; // NOT end of row gridbag.setConstraints(addButton, c); add(addButton); c.gridwidth = GridBagConstraints.REMAINDER; // end of row gridbag.setConstraints(removeButton, c); add(removeButton); c.weighty = 1.0; // Button area and message area have equal height. gridbag.setConstraints(buttonPanel, c); add(buttonPanel); setPreferredSize(new Dimension(400, 400)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:WindowEventDemo.java
private void addComponentsToPane() { display = new JTextArea(); display.setEditable(false);/* www .j a v a2s . c o m*/ JScrollPane scrollPane = new JScrollPane(display); scrollPane.setPreferredSize(new Dimension(500, 450)); getContentPane().add(scrollPane, BorderLayout.CENTER); addWindowListener(this); addWindowFocusListener(this); addWindowStateListener(this); checkWM(); }
From source file:events.MouseMotionEventDemo.java
public MouseMotionEventDemo() { super(new GridLayout(0, 1)); blankArea = new BlankArea(Color.YELLOW); add(blankArea);/*from w w w .j ava2 s . c o m*/ textArea = new JTextArea(); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setPreferredSize(new Dimension(200, 75)); add(scrollPane); //Register for mouse events on blankArea and panel. blankArea.addMouseMotionListener(this); addMouseMotionListener(this); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:teambootje.A5.java
/** * Creates new form A5/*from w w w. ja va 2 s .c om*/ */ public A5() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 5"); ImageIcon icon = new ImageIcon("img/bootje.jpg"); setIconImage(icon.getImage()); // back BTN JButton back = new JButton("Back"); add(back, BorderLayout.NORTH); back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); // panel en Label JPanel ana = new JPanel(); add(ana, BorderLayout.CENTER); //tabel String sql = "SELECT Leeftijd, COUNT(*) AS Aantal FROM persoon GROUP BY Leeftijd"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String age = rs.getString("Leeftijd"); int aantal = rs.getInt("Aantal"); String[] row = new String[rs.getMetaData().getColumnCount()]; for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { row[i - 1] = rs.getString(i); } list.add(row); //chart JButton chart = new JButton("Chart"); add(chart, BorderLayout.SOUTH); chart.addActionListener(new ActionListener() { String leeftijd = age; int a1 = aantal; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("Niet vrijgegeven", a1); JFreeChart chart = ChartFactory.createPieChart3D("Aantal mensen per leeftijd", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal mensen per leeftijd", chart); pie.setVisible(true); pie.setSize(500, 500); pie.setLocationRelativeTo(null); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); } } catch (SQLException e) { JOptionPane.showMessageDialog(null, e); } Object[][] array = new Object[list.size()][]; Object columnNames[] = { "Leeftijd", "Aantal" }; list.toArray(array); JTable table = new JTable(array, columnNames); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(400, 400)); ana.add(scroll); }