@Override public void componentResized(ComponentEvent e) { Component source = e.getComponent(); scroller.setSize(source.getSize()); scroller.revalidate(); } });
@Override public void componentResized(ComponentEvent e) { int width = e.getComponent().getWidth(); int height = e.getComponent().getHeight(); BattlefieldPanel.this.jScrollPane.setSize(width, height); BattlefieldPanel.this.width = width; sortLayout(); } });
@Override public void componentResized(ComponentEvent e) { // listen to changes of JLayeredPane size JScrollIndicator.this.scrollPane.setSize(JScrollIndicator.this.getSize()); JScrollIndicator.this.scrollPane.getViewport().revalidate(); JScrollIndicator.this.controlPanel.setSize(JScrollIndicator.this.getSize()); JScrollIndicator.this.controlPanel.revalidate(); } }
JPanel tablePanel = new JPanel(new BorderLayout(5, 5)); JScrollPane tableScroll = new JScrollPane(menuItemsTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); tableScroll.setSize(200, 170); tableScroll.setPreferredSize(new Dimension(200, 170)); tableScroll.setMaximumSize(new Dimension(200, 170));
protected void initSize() { if (scrollPane != null) { scrollPane.setSize(this.getSize()); } // scrollPane.setPreferredSize(this.getSize()); }
protected void initSize() { if (scrollPane != null) { scrollPane.setSize(this.getSize()); } // scrollPane.setPreferredSize(this.getSize()); }
final JScrollPane scrollEditor = new JScrollPane(editor, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); final JSplitPane innerPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, scrollEditor, scrollPreview); innerPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { editor.setSize(innerPane.getLeftComponent().getBounds().width, editor.getHeight() - 10); // If you want more edge space make 10 to 15 or 20 scrollEditor.setSize(innerPane.getLeftComponent().getBounds().width, editor.getHeight()); } });
@Override public void componentResized(ComponentEvent e) { Component source =e.getComponent(); scroller.setSize(source.getSize()); scroller.revalidate(); } });
public SimpleInfoBox( final String title, final String text ) { frame = new JFrame( title ); final JTextArea textarea = new JTextArea( text ); final JPanel panel = new JPanel(); panel.add( textarea, BorderLayout.CENTER ); final JScrollPane pane = new JScrollPane( panel ); frame.add( pane, BorderLayout.CENTER ); frame.pack(); final Dimension d = pane.getSize(); d.setSize( d.width + 20, d.height + 10 ); pane.setSize( d ); pane.setPreferredSize( d ); frame.setPreferredSize( d ); frame.pack(); frame.setVisible( true ); } }
// the panel JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new GridBagLayout()); buttonPanel.setSize(new Dimension(400, 300)); // whatever // the scrollpane JScrollPane pane = new JScrollPane(); pane.setSize(new Dimension(400, 300)); // whatever // GridBagConstraint for button GridBagConstraints constraint = new GridBagConstraints(); constraint.anchor = GridBagConstraints.CENTER; constraint.fill = GridBagConstraints.NONE; constraint.gridx = 0; constraint.gridy = GridBagConstraints.RELATIVE; constraint.weightx = 1.0f; constraint.weighty = 1.0f; int sizeOfButtons = 50; for(int i = 0; i < sizeOfButtons; i++) { JButton button = new JButton(); button.setText("Button #" + i); // other attributes you will set buttonPanel.add(button, constraint); } pane.setViewportView(buttonPanel); this.rootPane.add(pane); // or other panel etc. pane.updateUI();
private JComponent createCode() { final JLabel codeLabel = new JLabel(ImageCreator.IMG_OWASP); codeLabel.setLocation(20, 45); codeLabel.setSize(100, 100); final URL codeURL = ClassLoader.getSystemClassLoader() .getResource("LICENSE/CODE.txt"); JEditorPane code; try { code = new JEditorPane(codeURL); } catch (final IOException eAbout) { code = new JEditorPane(); code.setText("Code information cannot be found!"); } code.setEditable(false); code.addKeyListener(this); final JScrollPane codeScroll = new JScrollPane(code); codeScroll.setVerticalScrollBarPolicy(20); codeScroll.setHorizontalScrollBarPolicy(30); codeScroll.setLocation(140, 5); codeScroll.setSize(290, 185); final JPanel codePanel = new JPanel(); codePanel.setLayout(null); codePanel.add(codeLabel); codePanel.add(codeScroll); return codePanel; }
disclaimerScroll.setHorizontalScrollBarPolicy(30); disclaimerScroll.setLocation(140, 5); disclaimerScroll.setSize(290, 185);
private void draw() { JPanel panel = new JPanel(); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); panel.setLayout(gbl); for (int i = 0; i < paramLabels.length; i++) { fields[i].addActionListener(this); // Ajout du panel de la chaine buildConstraints(c, 0, i, 1, 1, 50, 20); c.anchor = GridBagConstraints.EAST; gbl.setConstraints(labels[i], c); panel.add(labels[i]); // Ajout du panel de la chaine buildConstraints(c, 1, i, 1, 1, 50, 20); c.fill = GridBagConstraints.HORIZONTAL; gbl.setConstraints(fields[i], c); panel.add(fields[i]); } JScrollPane scrollPane = new JScrollPane(panel); scrollPane.setPreferredSize(getSize()); scrollPane.setSize(getSize()); setLayout(new BorderLayout()); add(scrollPane, BorderLayout.CENTER); }
private void draw() { JPanel panel = new JPanel(); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); panel.setLayout(gbl); for (int i = 0; i < paramLabels.length; i++) { fields[i].addActionListener(this); // Ajout du panel de la chaine buildConstraints(c, 0, i, 1, 1, 50, 20); c.anchor = GridBagConstraints.EAST; gbl.setConstraints(labels[i], c); panel.add(labels[i]); // Ajout du panel de la chaine buildConstraints(c, 1, i, 1, 1, 50, 20); c.fill = GridBagConstraints.HORIZONTAL; gbl.setConstraints(fields[i], c); panel.add(fields[i]); } JScrollPane scrollPane = new JScrollPane(panel); scrollPane.setPreferredSize(getSize()); scrollPane.setSize(getSize()); setLayout(new BorderLayout()); add(scrollPane, BorderLayout.CENTER); }
public void setSize(int width, int height){ int maxWidth = width; int maxHeight = height; minSize.width = minSizeDefault.width; minSize.height = minSizeDefault.height; setMinimumSize(minSize); Dimension ps = getPreferredSize(); /* Add size of the vertical scrollbar by default. This could be improved * to be done only if the height exceeds the bounds. */ ps.width += scrollBarSize.width; ps.width = Math.max(Math.max(ps.width, minSize.width), getTitleComponentPreferredSize().width); maxWidth = Math.min(maxWidth, maxSize.width); maxHeight = Math.min(maxHeight, maxSize.height); boolean displayHorizontalScrollbar = (ps.width-scrollBarSize.width)>maxWidth; if (ps.width > maxWidth) { ps.width = maxWidth; if (displayHorizontalScrollbar){ ps.height += scrollBarSize.height; // will show horizontal scrollbar minSize.height += scrollBarSize.height; setMinimumSize(minSize); } } ps.height = Math.min(Math.max(ps.height, minSize.height), maxHeight); super.setSize(ps.width, ps.height); }
public void setSize(int width, int height){ int maxWidth = width; int maxHeight = height; minSize.width = minSizeDefault.width; minSize.height = minSizeDefault.height; setMinimumSize(minSize); Dimension ps = getPreferredSize(); /* Add size of the vertical scrollbar by default. This could be improved * to be done only if the height exceeds the bounds. */ ps.width += scrollBarSize.width; ps.width = Math.max(Math.max(ps.width, minSize.width), getTitleComponentPreferredSize().width); maxWidth = Math.min(maxWidth, maxSize.width); maxHeight = Math.min(maxHeight, maxSize.height); boolean displayHorizontalScrollbar = (ps.width-scrollBarSize.width)>maxWidth; if (ps.width > maxWidth) { ps.width = maxWidth; if (displayHorizontalScrollbar){ ps.height += scrollBarSize.height; // will show horizontal scrollbar minSize.height += scrollBarSize.height; setMinimumSize(minSize); } } ps.height = Math.min(Math.max(ps.height, minSize.height), maxHeight); super.setSize(ps.width, ps.height); }
JTree tree; JScrollPane scrollPane; DefaultMutableTreeNode root = new DefaultMutableTreeNode("RootNode"); public Tree() { setVisible(true); setSize(100, 300); createChildNodes(root); tree = new JTree(root); tree.setVisible(true); tree.setSize(100, 300); scrollPane = new JScrollPane(tree); scrollPane.add(tree); scrollPane.setVisible(true); scrollPane.setSize(100, 300); scrollPane.setViewportView(this); scrollPane.setBackground(Color.red); }
/** * Create comment cached image * * @param forceRefresh * @param w * @param h */ public void createCommentImage(boolean forceRefresh, int w, int h) { if (forceRefresh || scrollPane.getWidth() != w || scrollPane.getHeight() != h) { if (w > 0 && h > 0) { scrollPane.setSize(w, h); cachedCommentImage = new BufferedImage(scrollPane.getWidth(), scrollPane.getHeight(), TYPE_INT_ARGB); Graphics2D g2 = cachedCommentImage.createGraphics(); scrollPane.doLayout(); scrollPane.validate(); scrollPane.printAll(g2); g2.dispose(); } } }
public void resize() { int height = tipsList.getFixedCellHeight(); int size = tipsModel.size(); if(size > 0) { int width = 0; for(int i=0; i<tipsModel.size(); i++) { String e = (String)tipsModel.getElementAt(i); TextLayout layout = new TextLayout(e, tipsList.getFont(), ((Graphics2D)tipsList.getGraphics()).getFontRenderContext()); width = Math.max(width, (int)layout.getBounds().getWidth()); } height = height*Math.min(VISIBLE_TIPS, size)+5; Dimension d = new Dimension(width+10, height); setSize(d); tipsList.setSize(d); tipsScrollPane.setSize(d); } }
/** @param parent */ public void layoutContainer(Container parent) { Dimension margin_sz = m_colmargin.getPreferredSize(); Insets insets = parent.getInsets(); int colm_x = insets.left + margin_sz.width; int colm_y = insets.top; int colm_width = parent.getWidth() - insets.right - colm_x; int colm_height = margin_sz.height; int rowm_x = insets.left; int rowm_y = insets.top + margin_sz.height; int rowm_width = margin_sz.width; int rowm_height = parent.getHeight() - insets.bottom - rowm_y; m_scroll.setLocation(colm_x, rowm_y); m_scroll.setSize(colm_width, rowm_height); m_colmargin.setLocation(colm_x, colm_y); m_colmargin.setSize(colm_width, colm_height); m_rowmargin.setLocation(rowm_x, rowm_y); m_rowmargin.setSize(rowm_width, rowm_height); }