javax.swing.ScrollPaneLayout Java Examples

The following examples show how to use javax.swing.ScrollPaneLayout. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MarvinPluginHistory.java    From marvinproject with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Constructs a new PluginHistory.
 */
public MarvinPluginHistory()
{
	frameHistory = this;
	
	this.setLayout(new BorderLayout ());

	setResizable(true);
	setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	setTitle("Plug-ins history");
	
	listMarvinImage = new LinkedList<MarvinImage>();
	listMarvinAttributes = new LinkedList<MarvinAttributes>();
	listPluginName = new LinkedList<String>();
	
	panelPlugin = new JPanel();
	
	scrollPanelPlugins = new JScrollPane
	(
		panelPlugin, 
		ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
		ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
	);
	
	
	scrollPanelPlugins.setLayout(new ScrollPaneLayout());		
	add(scrollPanelPlugins);
	
	panelButtonHistory = new JPanel();
			
	buttonExportHistortAsImage = new JButton("Export as Image");
	buttonExportHistortAsImage.addActionListener(new ExportButtonHandler());
	buttonExportHistortAsImage.setMnemonic('I');
	
	// the action listener is still not created
	// so no button appears
	//btnExportHistoricText = new JButton ("Export as Text");
	//btnExportHistoricText.addActionListener (new ExportTexButtonHandler ());
	// ActionListener "ExportTextButtonHandler" need to be created!!!
	//btnExportHistoricText.setMnemonic('T');

	panelButtonHistory.add(buttonExportHistortAsImage);
	//jpBtnHistoric.add (btnExportHistoricText);

	this.add(panelButtonHistory, BorderLayout.PAGE_END);
}
 
Example #2
Source File: CustomScroll.java    From mars-sim with GNU General Public License v3.0 3 votes vote down vote up
public CustomScroll(JComponent component) {
        scr = new JScrollPane(component);
        scr.setBorder(null);
        scr.setViewportBorder(null);
        scr.setBorder(BorderFactory.createEmptyBorder());
        scr.getViewport().setOpaque(false);
//        scr.setOpaque(false);
//        scr.setBackground(new Color(0, 0, 0, 5));
        verticalScrollBar = scr.getVerticalScrollBar();
        verticalScrollBar.setVisible(false);
        verticalScrollBar.setOpaque(false);
        verticalScrollBar.setUI(new MyScrollBarUI());
        verticalScrollBar.setUnitIncrement(16);

        horizontalScrollBar = scr.getHorizontalScrollBar();
        horizontalScrollBar.setVisible(false);
        horizontalScrollBar.setOpaque(false);
        horizontalScrollBar.setUI(new MyScrollBarUI());

        JLayeredPane layeredPane = new JLayeredPane();
        layeredPane.setLayer(verticalScrollBar, JLayeredPane.PALETTE_LAYER);
        layeredPane.setLayer(horizontalScrollBar, JLayeredPane.PALETTE_LAYER);

        scr.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        scr.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scr.setLayout(new ScrollPaneLayout() {
            @Override
            public void layoutContainer(Container parent) {
                viewport.setBounds(0, 0, getWidth(), getHeight());
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        displayScrollBarsIfNecessary(viewport);
                    }
                });
            }
        });

        layeredPane.add(horizontalScrollBar);
        layeredPane.add(verticalScrollBar);
        layeredPane.add(scr);

        setLayout(new BorderLayout() {
            @Override
            public void layoutContainer(Container target) {
                super.layoutContainer(target);
                int width = getWidth();
                int height = getHeight();
                scr.setBounds(0, 0, width, height);

                int scrollBarSize = 10;
                int cornerOffset = verticalScrollBar.isVisible() &&
                        horizontalScrollBar.isVisible() ? scrollBarSize : 0;
                if (verticalScrollBar.isVisible()) {
                    verticalScrollBar.setBounds(width - scrollBarSize, 0,
                            scrollBarSize, height - cornerOffset);
                }
                if (horizontalScrollBar.isVisible()) {
                    horizontalScrollBar.setBounds(0, height - scrollBarSize,
                            width - cornerOffset, scrollBarSize);
                }
            }
        });
        add(layeredPane, BorderLayout.CENTER);
        layeredPane.setBackground(Color.BLUE);
    }