Java Code Examples for javax.swing.JLayeredPane#add()

The following examples show how to use javax.swing.JLayeredPane#add() . 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: LuckMetalRootPaneUI.java    From littleluck with Apache License 2.0 6 votes vote down vote up
protected void installTitlePane(JRootPane root, LuckTitlePanel titlePane, Window window)
{
    JLayeredPane layeredPane = root.getLayeredPane();

    JComponent oldTitlePane = getTitlePane();

    if (oldTitlePane != null)
    {
        oldTitlePane.setVisible(false);

        layeredPane.remove(oldTitlePane);
    }

    if (titlePane != null)
    {
    	titlePane.setOpaque(true);
    	
        layeredPane.add(titlePane, JLayeredPane.FRAME_CONTENT_LAYER);

        titlePane.setVisible(true);
    }

    this.titlePane = titlePane;
}
 
Example 2
Source File: SeaGlassRootPaneUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the window title pane -- the JComponent used to provide a plaf a way
 * to override the native operating system's window title pane with one
 * whose look and feel are controlled by the plaf. The plaf creates and sets
 * this value; the default is null, implying a native operating system
 * window title pane.
 *
 * @param root      content the <code>JComponent</code> to use for the
 *                  window title pane.
 * @param titlePane the SeaGlassTitlePane.
 */
private void setTitlePane(JRootPane root, JComponent titlePane) {
    JLayeredPane layeredPane  = root.getLayeredPane();
    JComponent   oldTitlePane = getTitlePane();

    if (oldTitlePane != null) {
        oldTitlePane.setVisible(false);
        layeredPane.remove(oldTitlePane);
    }

    if (titlePane != null) {
        layeredPane.add(titlePane, JLayeredPane.FRAME_CONTENT_LAYER);
        titlePane.setVisible(true);
    }

    this.titlePane = titlePane;
}
 
Example 3
Source File: DesktopImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates a new instance of DesktopImpl */
public DesktopImpl () {
    // layered pane with absolute positioning, to enable overlapping
    layeredPane = new JLayeredPane();
    layeredPane.setLayout(new LayeredLayout());
    // desktop represents regular layer of layeredPane
    desktop = new JPanel() {
        @Override
        public boolean isOpaque() {
            if( UIManager.getBoolean( "NbMainWindow.showCustomBackground" ) ) //NOI18N
                return false;
            return super.isOpaque();
        }

        @Override
        public void updateUI() {
            Mutex.EVENT.readAccess( new Runnable() {
                @Override
                public void run() {
                    superUpdateUI();
                }
            });
        }

        private void superUpdateUI() {
            super.updateUI();
        }
    };
    desktop.setLayout(new GridBagLayout());
    Color bkColor = UIManager.getColor("NbSplitPane.background"); //NOI18N
    if( null != bkColor ) {
        desktop.setBackground(bkColor);
        desktop.setOpaque(true);
    }
    layeredPane.add(desktop);
}
 
Example 4
Source File: javax_swing_JLayeredPane.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void init(JLayeredPane pane, int layer, int x, int y, int w, int h, Color color) {
    JPanel panel = new JPanel();
    panel.setBackground(color);
    panel.setLocation(x, y);
    panel.setSize(w, h);
    pane.add(panel, new Integer(layer));
}
 
Example 5
Source File: CursorOverlappedPanelsTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void createAndShowGUI() {
    final JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLayeredPane layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(new Dimension(400, 400));
    JPanel enabledPanel = createPanel(new Point(10, 10), true);
    JPanel disabledPanel = createPanel(new Point(100, 100), false);
    layeredPane.add(disabledPanel, JLayeredPane.PALETTE_LAYER);
    layeredPane.add(enabledPanel, JLayeredPane.DEFAULT_LAYER);

    frame.getContentPane().add(layeredPane);
    frame.pack();
    frame.setVisible(true);
}
 
Example 6
Source File: CursorOverlappedPanelsTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void createAndShowGUI() {
    final JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLayeredPane layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(new Dimension(400, 400));
    JPanel enabledPanel = createPanel(new Point(10, 10), true);
    JPanel disabledPanel = createPanel(new Point(100, 100), false);
    layeredPane.add(disabledPanel, JLayeredPane.PALETTE_LAYER);
    layeredPane.add(enabledPanel, JLayeredPane.DEFAULT_LAYER);

    frame.getContentPane().add(layeredPane);
    frame.pack();
    frame.setVisible(true);
}
 
Example 7
Source File: FlatRootPaneUI.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
protected void setTitlePane( FlatTitlePane newTitlePane ) {
	JLayeredPane layeredPane = rootPane.getLayeredPane();

	if( titlePane != null )
		layeredPane.remove( titlePane );

	if( newTitlePane != null )
		layeredPane.add( newTitlePane, TITLE_PANE_LAYER );

	titlePane = newTitlePane;
}
 
Example 8
Source File: CursorOverlappedPanelsTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void createAndShowGUI() {
    final JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLayeredPane layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(new Dimension(400, 400));
    JPanel enabledPanel = createPanel(new Point(10, 10), true);
    JPanel disabledPanel = createPanel(new Point(100, 100), false);
    layeredPane.add(disabledPanel, JLayeredPane.PALETTE_LAYER);
    layeredPane.add(enabledPanel, JLayeredPane.DEFAULT_LAYER);

    frame.getContentPane().add(layeredPane);
    frame.pack();
    frame.setVisible(true);
}
 
Example 9
Source File: CursorOverlappedPanelsTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void createAndShowGUI() {
    final JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLayeredPane layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(new Dimension(400, 400));
    JPanel enabledPanel = createPanel(new Point(10, 10), true);
    JPanel disabledPanel = createPanel(new Point(100, 100), false);
    layeredPane.add(disabledPanel, JLayeredPane.PALETTE_LAYER);
    layeredPane.add(enabledPanel, JLayeredPane.DEFAULT_LAYER);

    frame.getContentPane().add(layeredPane);
    frame.pack();
    frame.setVisible(true);
}
 
Example 10
Source File: TextHighlightingDemo.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void installInLayeredPane(JComponent component) {
    JLayeredPane layeredPane = getRootPane().getLayeredPane();
    layeredPane.add(component, JLayeredPane.PALETTE_LAYER, 20);
    Dimension size = component.getPreferredSize();
    component.setSize(size);
    component.setLocation((getWidth() - size.width) / 2,
            (getHeight() - size.height) / 2);
    component.revalidate();
    component.setVisible(true);
}
 
Example 11
Source File: CursorOverlappedPanelsTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void createAndShowGUI() {
    final JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLayeredPane layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(new Dimension(400, 400));
    JPanel enabledPanel = createPanel(new Point(10, 10), true);
    JPanel disabledPanel = createPanel(new Point(100, 100), false);
    layeredPane.add(disabledPanel, JLayeredPane.PALETTE_LAYER);
    layeredPane.add(enabledPanel, JLayeredPane.DEFAULT_LAYER);

    frame.getContentPane().add(layeredPane);
    frame.pack();
    frame.setVisible(true);
}
 
Example 12
Source File: javax_swing_JLayeredPane.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void init(JLayeredPane pane, int layer, int x, int y, int w, int h, Color color) {
    JPanel panel = new JPanel();
    panel.setBackground(color);
    panel.setLocation(x, y);
    panel.setSize(w, h);
    pane.add(panel, new Integer(layer));
}
 
Example 13
Source File: CursorOverlappedPanelsTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void createAndShowGUI() {
    final JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLayeredPane layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(new Dimension(400, 400));
    JPanel enabledPanel = createPanel(new Point(10, 10), true);
    JPanel disabledPanel = createPanel(new Point(100, 100), false);
    layeredPane.add(disabledPanel, JLayeredPane.PALETTE_LAYER);
    layeredPane.add(enabledPanel, JLayeredPane.DEFAULT_LAYER);

    frame.getContentPane().add(layeredPane);
    frame.pack();
    frame.setVisible(true);
}
 
Example 14
Source File: QPopup.java    From pumpernickel with MIT License 4 votes vote down vote up
private boolean showUsingRootPaneContainer(Point screenLoc,
		CalloutType calloutType) {
	Window ownerWindow = owner instanceof Window ? (Window) owner
			: SwingUtilities.getWindowAncestor(owner);
	RootPaneContainer rpc = ownerWindow instanceof RootPaneContainer
			? (RootPaneContainer) ownerWindow
			: null;

	if (rpc == null)
		return false;

	JLayeredPane layeredPane = rpc.getLayeredPane();
	Point layeredPaneLoc = new Point(screenLoc);
	SwingUtilities.convertPointFromScreen(layeredPaneLoc, layeredPane);

	if (calloutType == null) {
		ui.setCalloutType(CalloutType.TOP_CENTER);
		ui.setCalloutSize(0);
	} else {
		ui.setCalloutType(calloutType);
		ui.setCalloutSize(CALLOUT_SIZE);
	}

	contents.validate();
	contents.setSize(contents.getPreferredSize());

	Rectangle layeredPaneBounds = new Rectangle(layeredPaneLoc.x,
			layeredPaneLoc.y, contents.getWidth(), contents.getHeight());
	if (calloutType != null) {
		Point calloutTip = ui.getCalloutTip(contents);
		layeredPaneBounds.x -= calloutTip.x;
		layeredPaneBounds.y -= calloutTip.y;
	}

	if (new Rectangle(0, 0, layeredPane.getWidth(), layeredPane.getHeight())
			.contains(layeredPaneBounds)) {

		if (contents.getParent() != layeredPane) {
			hide();
			layeredPane.add(contents, JLayeredPane.POPUP_LAYER);
		}

		contents.setBounds(layeredPaneBounds);
		contents.setVisible(true);

		return true;
	}
	return false;
}
 
Example 15
Source File: SamplesOrganizerPane.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
/**
 *
 *
 * @param title
 * @param x
 * @param y
 * @param myWidth
 * @param myHeight
 * @param tripoliSamples
 * @param projectManager the value of projectManager
 */
public SamplesOrganizerPane(//
        String title, int x, int y, int myWidth, int myHeight, ArrayList<AbstractTripoliSample> tripoliSamples, ProjectManagerSubscribeInterface projectManager) {

    this.titleLabel = new JLabel(title);
    this.titleLabel.setBounds(2, 2, 150, 15);
    this.add(this.titleLabel, DEFAULT_LAYER);

    this.myWidth = myWidth;
    this.myHeight = myHeight;

    this.setBounds(x, y, myWidth, myHeight);
    this.setOpaque(true);

    this.tripoliSamples = tripoliSamples;

    sampleFractionLists_pane = new JLayeredPane();

    // populate list boxes
    sampleDisplayPanes = new ArrayList<>();

    // walk the samples
    for (int i = 0; i < tripoliSamples.size(); i++) {
        ActionListener closeButtonActionListener = new CloseSampleButtonActionListener();
        SampleFractionListDisplayPane sampleDisplayPane
                =//
                new SampleFractionListDisplayPane( //
                        tripoliSamples.get(i), //
                        closeButtonActionListener, //
                        this, //
                        projectManager);
        ((CloseSampleButtonActionListener) closeButtonActionListener).setSampleDisplayPane(sampleDisplayPane);
        sampleDisplayPanes.add(sampleDisplayPane);
        sampleFractionLists_pane.add(sampleDisplayPane);
    }

    sampleFractionLists_scroll = new javax.swing.JScrollPane();
    sampleFractionLists_scroll.setAutoscrolls(true);
    sampleFractionLists_scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    this.add(sampleFractionLists_scroll, DEFAULT_LAYER);
    sampleFractionLists_scroll.setViewportView(sampleFractionLists_pane);

    // button to create additional SampleFractionListDisplayPanels
    addSampleButton = new ET_JButton("+");
    addSampleButton.setBounds(5, myHeight - 50, 15, 15);
    addSampleButton.addActionListener(new AddSampleButtonActionListener(this));
    this.add(addSampleButton, DEFAULT_LAYER);

    dndClipboardListItems = new DragAndDropListItemInterface[0];

    this.projectManager = projectManager;

    refreshSampleFractionListsPane();

}
 
Example 16
Source File: ChartPagePanel.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Responsible for creating the UI layout.
 *
 * @param chartPanel the panel of the chart
 * @param optionsPanel the options panel for changing settings
 * @param roiMaskSelector optional ROI mask selector, can be {@code null} if not wanted.
 */
protected void createUI(ChartPanel chartPanel, JPanel optionsPanel, RoiMaskSelector roiMaskSelector) {
    this.roiMaskSelector = roiMaskSelector;
    final JPanel extendedOptionsPanel = GridBagUtils.createPanel();
    GridBagConstraints extendedOptionsPanelConstraints = GridBagUtils.createConstraints("insets.left=4,insets.right=2,anchor=NORTHWEST,fill=HORIZONTAL,insets.top=2,weightx=1");
    GridBagUtils.addToPanel(extendedOptionsPanel, new JSeparator(), extendedOptionsPanelConstraints, "gridy=0");
    if (this.roiMaskSelector != null) {
        GridBagUtils.addToPanel(extendedOptionsPanel, this.roiMaskSelector.createPanel(), extendedOptionsPanelConstraints, "gridy=1,insets.left=-4");
        GridBagUtils.addToPanel(extendedOptionsPanel, new JPanel(), extendedOptionsPanelConstraints, "gridy=1,insets.left=-4");
    }
    GridBagUtils.addToPanel(extendedOptionsPanel, optionsPanel, extendedOptionsPanelConstraints, "insets.left=0,insets.right=0,gridy=2,fill=VERTICAL,fill=HORIZONTAL,weighty=1");
    GridBagUtils.addToPanel(extendedOptionsPanel, new JSeparator(), extendedOptionsPanelConstraints, "insets.left=4,insets.right=2,gridy=5,anchor=SOUTHWEST");

    final SimpleScrollPane optionsScrollPane = new SimpleScrollPane(extendedOptionsPanel,
                                                                    ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                                                                    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    optionsScrollPane.setBorder(null);
    optionsScrollPane.getVerticalScrollBar().setUnitIncrement(20);

    final JPanel rightPanel = new JPanel(new BorderLayout());
    rightPanel.add(createTopPanel(), BorderLayout.NORTH);
    rightPanel.add(optionsScrollPane, BorderLayout.CENTER);
    rightPanel.add(createChartBottomPanel(chartPanel), BorderLayout.SOUTH);

    final ImageIcon collapseIcon = UIUtils.loadImageIcon("icons/PanelRight12.png");
    final ImageIcon collapseRolloverIcon = ToolButtonFactory.createRolloverIcon(collapseIcon);
    final ImageIcon expandIcon = UIUtils.loadImageIcon("icons/PanelLeft12.png");
    final ImageIcon expandRolloverIcon = ToolButtonFactory.createRolloverIcon(expandIcon);

    hideAndShowButton = ToolButtonFactory.createButton(collapseIcon, false);
    hideAndShowButton.setToolTipText("Collapse Options Panel");
    hideAndShowButton.setName("switchToChartButton");
    hideAndShowButton.addActionListener(new ActionListener() {

        private boolean rightPanelShown;

        @Override
        public void actionPerformed(ActionEvent e) {
            rightPanel.setVisible(rightPanelShown);
            if (rightPanelShown) {
                hideAndShowButton.setIcon(collapseIcon);
                hideAndShowButton.setRolloverIcon(collapseRolloverIcon);
                hideAndShowButton.setToolTipText("Collapse Options Panel");
            } else {
                hideAndShowButton.setIcon(expandIcon);
                hideAndShowButton.setRolloverIcon(expandRolloverIcon);
                hideAndShowButton.setToolTipText("Expand Options Panel");
            }
            rightPanelShown = !rightPanelShown;
        }
    });

    backgroundPanel = new JPanel(new BorderLayout());
    backgroundPanel.add(chartPanel, BorderLayout.CENTER);
    backgroundPanel.add(rightPanel, BorderLayout.EAST);

    JLayeredPane layeredPane = new JLayeredPane();
    layeredPane.add(backgroundPanel, new Integer(0));
    layeredPane.add(hideAndShowButton, new Integer(1));
    add(layeredPane);
}
 
Example 17
Source File: TracerUPbRatiosAbstractDataView.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @param editable the value of editable
 */
@Override
protected void initView ( final boolean editable){
    super.initView( editable );

    JLabel tracerTypesLabel = new JLabel( "Choose Tracer Type (currently supported):" );

    tracerTypesLabel.setBounds( 25, 10, 350, 25 );
    setOpaqueWithLightGray( tracerTypesLabel );

    JLayeredPane tracerTypePane = new JLayeredPane();

    tracerTypePane.add( tracerTypesLabel, DEFAULT_LAYER );

    // set up Tracer Type chooser
    tracerTypeChooser.setBounds( 100, 40, 275, 25 );
    tracerTypeChooser.setFont(ReduxConstants.sansSerif_12_Bold );
    tracerTypeChooser.removeAllItems();
    TracerUPbTypesEnum[] supportedTypes = TracerUPbTypesEnum.getSupportedTypes();
    for (int i = 0; i < supportedTypes.length; i ++) {
        tracerTypeChooser.addItem( supportedTypes[i] );
    }
    tracerTypeChooser.setSelectedItem( TracerUPbTypesEnum.valueFromName( ((TracerUPbModel) dataModel).getTracerType() ) );
    tracerTypeChooser.setEnabled( editable );
    tracerTypeChooser.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed ( ActionEvent e ) {
            ((TracerUPbModel) dataModel)//
                    .setTracerType( (String) tracerTypeChooser.getSelectedItem().toString() );
            dataModel.initializeNewRatiosAndRhos( true );
            dataModel.initializeModel();

            // update valueModelPane to show current tracer type ratios and concentrations
            dataTabs.remove( valueModelsPanelView );
            matrixTabs.remove( correlationVarUnctMatrixView );
            matrixTabs.remove( covarianceVarUnctMatrixView );

            setupViews();
            initDataTabsValueModelPanel(0, 0 );
            initializeMatrixTabs();

            try {
                saveAndUpdateModelView( false );
            } catch (ETException ex) {
                new ETWarningDialog(ex).setVisible(true);
            }
        }
    } );

    setOpaqueWithLightGray( tracerTypeChooser );
    tracerTypePane.add( tracerTypeChooser, DEFAULT_LAYER );

    tracerTypeChooser.setEnabled( editable );

    setOpaqueWithLightGray( tracerTypePane );
    insertModelTab( "Tracer Type", tracerTypePane, 1 );
}
 
Example 18
Source File: NbEditorUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
    protected JComponent createExtComponent() {

        JTextComponent component = getComponent();
        
        JLayeredPane layers = new LayeredEditorPane(component);
        layers.add(component, JLayeredPane.DEFAULT_LAYER, 0);
//        MyInternalFrame window = new MyInternalFrame();
//        layers.add(window, JLayeredPane.PALETTE_LAYER);
//        window.show();

        // Add the scroll-pane with the component to the center
        JScrollPane scroller = new JScrollPane(layers);
        scroller.getViewport().setMinimumSize(new Dimension(4,4));

        // remove default scroll-pane border, winsys will handle borders itself 
        Border empty = BorderFactory.createEmptyBorder();
        // Important:  Do not delete or use null instead, will cause
        //problems on GTK L&F.  Must set both scroller border & viewport
        //border! - Tim
        scroller.setBorder(empty);
        scroller.setViewportBorder(empty);
        
        if (component.getClientProperty("nbeditorui.vScrollPolicy") != null) {
            scroller.setVerticalScrollBarPolicy(
                    (Integer)component.getClientProperty("nbeditorui.vScrollPolicy"));
        }
        if (component.getClientProperty("nbeditorui.hScrollPolicy") != null) {
            scroller.setHorizontalScrollBarPolicy(
                    (Integer)component.getClientProperty("nbeditorui.hScrollPolicy"));
        }
        // extComponent will be a panel
        JComponent ec = new JPanel(new BorderLayout());
        ec.putClientProperty(JTextComponent.class, component);
        ec.add(scroller);

        // Initialize sidebars
        // Need to clear the cache - it's null at this point when opening file but the sidebars
        // would be reused during L&F change (see BaseTextUI.UIWatcher) which would not work properly.
        CustomizableSideBar.resetSideBars(component);
        Map<SideBarPosition, JComponent> sideBars = CustomizableSideBar.getSideBars(component);
        processSideBars(sideBars, ec, scroller);
        
        if (listener == null){
            listener = new SideBarsListener(component);
            CustomizableSideBar.addChangeListener(NbEditorUtilities.getMimeType(component), listener);
        }
        
        // Initialize the corner component
        initGlyphCorner(scroller);

        return ec;
    }
 
Example 19
Source File: HexMap.java    From Rails with GNU General Public License v2.0 4 votes vote down vote up
public void addLayers(JLayeredPane p, int startingZOffset) {
    int z = startingZOffset;
    for (JComponent l : layers) {
        p.add(l, z++);
    }
}
 
Example 20
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);
    }