Example usage for javax.swing OverlayLayout OverlayLayout

List of usage examples for javax.swing OverlayLayout OverlayLayout

Introduction

In this page you can find the example usage for javax.swing OverlayLayout OverlayLayout.

Prototype

@ConstructorProperties({ "target" })
public OverlayLayout(Container target) 

Source Link

Document

Constructs a layout manager that performs overlay arrangement of the children.

Usage

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    panel.setLayout(new OverlayLayout(panel));

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.add("1", new JTextField("one"));
    tabbedPane.add("2", new JTextField("two"));
    tabbedPane.setAlignmentX(1.0f);//from   w ww  .jav a  2s.c  o  m
    tabbedPane.setAlignmentY(0.0f);

    JCheckBox checkBox = new JCheckBox("Add tab");
    checkBox.setOpaque(false);
    checkBox.setAlignmentX(1.0f);
    checkBox.setAlignmentY(0.0f);

    panel.add(checkBox);
    panel.add(tabbedPane);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel);
    frame.setSize(400, 100);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    panel.setLayout(new OverlayLayout(panel));

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.add("1", new JTextField("one"));
    tabbedPane.add("2", new JTextField("two"));
    tabbedPane.setAlignmentX(1.0f);/*from   w  w  w .  ja va  2 s  .  com*/
    tabbedPane.setAlignmentY(0.0f);

    JCheckBox checkBox = new JCheckBox("Check Me");
    checkBox.setOpaque(false);
    checkBox.setAlignmentX(1.0f);
    checkBox.setAlignmentY(0.0f);

    panel.add(checkBox);
    panel.add(tabbedPane);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel);
    frame.setLocationByPlatform(true);
    frame.setSize(400, 100);
    frame.setVisible(true);
}

From source file:OverlaySample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Overlay Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel() {
        public boolean isOptimizedDrawingEnabled() {
            return false;
        }/*www .  j ava 2s.c o  m*/
    };
    LayoutManager overlay = new OverlayLayout(panel);
    panel.setLayout(overlay);

    JButton button = new JButton("Small");
    button.setMaximumSize(new Dimension(25, 25));
    button.setBackground(Color.white);
    panel.add(button);

    button = new JButton("Medium");
    button.setMaximumSize(new Dimension(50, 50));
    button.setBackground(Color.gray);
    panel.add(button);

    button = new JButton("Large");
    button.setMaximumSize(new Dimension(100, 100));
    button.setBackground(Color.black);
    panel.add(button);

    frame.add(panel, BorderLayout.CENTER);

    frame.setSize(400, 300);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Overlay Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel() {
        public boolean isOptimizedDrawingEnabled() {
            return false;
        }/*w  ww  . j a  v a 2  s  . co m*/
    };
    LayoutManager overlay = new OverlayLayout(panel);
    panel.setLayout(overlay);

    JButton button = new JButton("Small");
    button.setMaximumSize(new Dimension(25, 25));
    button.setBackground(Color.white);
    button.setAlignmentX(0.0f);
    button.setAlignmentY(0.0f);
    panel.add(button);

    button = new JButton("Medium");
    button.setMaximumSize(new Dimension(50, 50));
    button.setBackground(Color.gray);
    button.setAlignmentX(0.0f);
    button.setAlignmentY(0.0f);
    panel.add(button);

    button = new JButton("Large");
    button.setMaximumSize(new Dimension(100, 100));
    button.setBackground(Color.black);
    button.setAlignmentX(0.0f);
    button.setAlignmentY(0.0f);
    panel.add(button);

    frame.add(panel, BorderLayout.CENTER);

    frame.setSize(400, 300);
    frame.setVisible(true);
}

From source file:OverlaySample.java

public static void main(String args[]) {

    ActionListener generalActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JComponent comp = (JComponent) actionEvent.getSource();
            System.out.println(actionEvent.getActionCommand() + ": " + comp.getBounds());
        }//from  w  w w  . j a  v  a 2s .  co m
    };

    ActionListener sizingActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            setupButtons(actionEvent.getActionCommand());
        }
    };

    JFrame frame = new JFrame("Overlay Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel();
    LayoutManager overlay = new OverlayLayout(panel);
    panel.setLayout(overlay);

    Object settings[][] = { { "Small", new Dimension(25, 25), Color.white },
            { "Medium", new Dimension(50, 50), Color.gray },
            { "Large", new Dimension(100, 100), Color.black } };
    JButton buttons[] = { smallButton, mediumButton, largeButton };

    for (int i = 0, n = settings.length; i < n; i++) {
        JButton button = buttons[i];
        button.addActionListener(generalActionListener);
        button.setActionCommand((String) settings[i][0]);
        button.setMaximumSize((Dimension) settings[i][1]);
        button.setBackground((Color) settings[i][2]);
        panel.add(button);
    }

    setupButtons(SET_CENTRAL);

    JPanel actionPanel = new JPanel();
    actionPanel.setBorder(BorderFactory.createTitledBorder("Change Alignment"));
    String actionSettings[] = { SET_MINIMUM, SET_MAXIMUM, SET_CENTRAL, SET_MIXED };
    for (int i = 0, n = actionSettings.length; i < n; i++) {
        JButton button = new JButton(actionSettings[i]);
        button.addActionListener(sizingActionListener);
        actionPanel.add(button);
    }

    Container contentPane = frame.getContentPane();
    contentPane.add(panel, BorderLayout.CENTER);
    contentPane.add(actionPanel, BorderLayout.SOUTH);

    frame.setSize(400, 300);
    frame.setVisible(true);
}

From source file:grafix.telas.JanelaGraficos.java

private void configurarJanela() {
    this.setBorder(BorderFactory.createEtchedBorder());
    this.setClosable(true);
    this.setIconifiable(false);
    this.setMaximizable(true);
    this.setResizable(true);
    this.setBounds(0, 0, 500, 500);
    this.setVisible(true);
    this.setTitle(getAcao().getCodAcao() + " - " + getAcao().getNomeAcao());
    this.setFrameIcon(new ImageIcon("resource/icones/grafix4.gif"));
    layersPane = new JLayeredPane();
    layersPane.setLayout(new OverlayLayout(layersPane));
    layersPane.add(getPanelGraficos(), JLayeredPane.FRAME_CONTENT_LAYER);
    layersPane.add(getPanelMolduras(), JLayeredPane.DRAG_LAYER);
    this.add(layersPane);
    this.addInternalFrameListener(new InternalFrameListener() {
        public void internalFrameActivated(InternalFrameEvent evt) {
            janelaAtivada();/* w ww  . ja  v  a  2s .c  o m*/
        }

        public void internalFrameClosed(InternalFrameEvent evt) {
            janelaFechada();
        }

        public void internalFrameClosing(InternalFrameEvent evt) {
        }

        public void internalFrameDeactivated(InternalFrameEvent evt) {
        }

        public void internalFrameDeiconified(InternalFrameEvent evt) {
        }

        public void internalFrameIconified(InternalFrameEvent evt) {
        }

        public void internalFrameOpened(InternalFrameEvent evt) {
        }
    });
}

From source file:lisong_mechlab.view.graphs.DamageGraph.java

/**
 * Creates and displays the {@link DamageGraph}.
 * //  w  w w .ja v a2  s . co  m
 * @param aLoadout
 *            Which load out the diagram is for.
 * @param anXbar
 *            A {@link MessageXBar} to listen for changes to the loadout on.
 * @param aMaxSustainedDpsMetric
 *            A {@link MaxSustainedDPS} instance to use in calculation.
 */
public DamageGraph(LoadoutBase<?> aLoadout, MessageXBar anXbar, MaxSustainedDPS aMaxSustainedDpsMetric) {
    super("Max Sustained DPS over range for " + aLoadout);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    anXbar.attach(this);

    loadout = aLoadout;
    maxSustainedDPS = aMaxSustainedDpsMetric;
    chartPanel = new ChartPanel(makechart());
    setContentPane(chartPanel);
    chartPanel.getChart().getLegend().setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chartPanel.getChart().getLegend().setVerticalAlignment(VerticalAlignment.TOP);

    LegendTitle legendTitle = chartPanel.getChart().getLegend();
    XYTitleAnnotation titleAnnotation = new XYTitleAnnotation(0.98, 0.98, legendTitle,
            RectangleAnchor.TOP_RIGHT);
    titleAnnotation.setMaxWidth(0.4);
    ((XYPlot) (chartPanel.getChart().getPlot())).addAnnotation(titleAnnotation);
    chartPanel.getChart().removeLegend();

    chartPanel.setLayout(new OverlayLayout(chartPanel));
    JButton button = new JButton(
            new OpenHelp("What is this?", "Max-sustained-dps-graph", KeyStroke.getKeyStroke('w')));
    button.setMargin(new Insets(10, 10, 10, 10));
    button.setFocusable(false);
    button.setAlignmentX(Component.RIGHT_ALIGNMENT);
    button.setAlignmentY(Component.BOTTOM_ALIGNMENT);
    chartPanel.add(button);

    setIconImage(ProgramInit.programIcon);
    setSize(800, 600);
    setVisible(true);
}

From source file:lisong_mechlab.view.graphs.SustainedDpsGraph.java

/**
 * Creates and displays the {@link SustainedDpsGraph}.
 * //w  ww . j  a  va2s. c  o  m
 * @param aLoadout
 *            Which load out the diagram is for.
 * @param aXbar
 *            A {@link MessageXBar} to listen for changes to the loadout on.
 * @param aMaxSustainedDpsMetric
 *            A {@link MaxSustainedDPS} instance to use in calculation.
 */
public SustainedDpsGraph(LoadoutBase<?> aLoadout, MessageXBar aXbar, MaxSustainedDPS aMaxSustainedDpsMetric) {
    super("Max Sustained DPS over range for " + aLoadout);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    aXbar.attach(this);

    loadout = aLoadout;
    maxSustainedDPS = aMaxSustainedDpsMetric;
    chartPanel = new ChartPanel(makechart());
    setContentPane(chartPanel);

    chartPanel.setLayout(new OverlayLayout(chartPanel));
    JButton button = new JButton(
            new OpenHelp("What is this?", "Max-sustained-dps-graph", KeyStroke.getKeyStroke('w')));
    button.setMargin(new Insets(5, 5, 5, 5));
    button.setFocusable(false);
    button.setAlignmentX(Component.RIGHT_ALIGNMENT);
    button.setAlignmentY(Component.TOP_ALIGNMENT);
    chartPanel.add(button);

    setIconImage(ProgramInit.programIcon);
    setSize(800, 600);
    setVisible(true);
}

From source file:au.com.jwatmuff.eventmanager.gui.scoreboard.ScoreboardDisplayPanel.java

protected ScoreboardDisplayPanel(ScoreboardLayout scoreboardLayout) {
    this.scoreboardLayout = scoreboardLayout;

    ScalableAbsoluteLayout layout;/*www. j a  va 2  s . c  o m*/

    setLayout(new GridLayout(1, 1));

    layeredPane = new JLayeredPane();
    layeredPane.setLayout(new OverlayLayout(layeredPane));
    add(layeredPane);

    /*
     * Image screen layer
     */
    imageLayer = new JXImagePanel();
    imageLayer.setVisible(false);
    imageLayer.setStyle(JXImagePanel.Style.SCALED_KEEP_ASPECT_RATIO);
    imageLayer.setBackground(Color.BLACK);
    layeredPane.add(imageLayer, new Integer(13));

    /*
     * No fight screen layer
     */
    noFightLayer = new JPanel();
    noFightLayer.setOpaque(true);
    noFightLayer.setVisible(false);
    layeredPane.add(noFightLayer, new Integer(12));
    layout = new ScalableAbsoluteLayout(noFightLayer, 16, 12);
    noFightLayer.setLayout(layout);

    layout.addComponent(new ScalableLabel("No Fight"), 4, 4, 8, 4);
    /*
     * Player vs Player layer
     */
    vsLayer = new JPanel();
    vsLayer.setOpaque(true);
    vsLayer.setVisible(false);
    layeredPane.add(vsLayer, new Integer(11));
    layout = new ScalableAbsoluteLayout(vsLayer, 16, 12);
    vsLayer.setLayout(layout);
    vsPlayer = new ScalableLabel[] { new ScalableLabel("Player 1"), new ScalableLabel("Player 2") };
    vs = new ScalableLabel("vs");
    vsDivision = new ScalableLabel(" ");
    layout.addComponent(vsPlayer[0], 1, 1, 11, 3);
    layout.addComponent(vsPlayer[1], 4, 8, 11, 3);
    layout.addComponent(vs, 7, 5, 2, 2);
    layout.addComponent(vsDivision, scoreboardLayout.getDivisionRect());

    /*
     * Pending fight layer
     */
    pendingFightLayer = new JPanel();
    pendingFightLayer.setOpaque(true);
    pendingFightLayer.setVisible(false);
    layeredPane.add(pendingFightLayer, new Integer(10));
    layout = new ScalableAbsoluteLayout(pendingFightLayer, 16, 12);
    pendingFightLayer.setLayout(layout);
    pendingPlayer = new ScalableLabel[] { new ScalableLabel("Player 1"), new ScalableLabel("Player 2") };
    pendingFightTimer = new ScalableLabel[] { new ScalableLabel("0:00"), new ScalableLabel("0:00") };
    pendingDivision = new ScalableLabel(" ");
    layout.addComponent(pendingPlayer[0], 1, 2.5, 6, 1.5);
    layout.addComponent(pendingPlayer[1], 9, 2.5, 6, 1.5);
    layout.addComponent(pendingFightTimer[0], 2, 5, 4, 2);
    layout.addComponent(pendingFightTimer[1], 10, 5, 4, 2);
    layout.addComponent(pendingDivision, scoreboardLayout.getDivisionRect());

    /*
     * Winning result layer
     */
    resultLayer = new JPanel();
    resultLayer.setOpaque(false);
    layeredPane.add(resultLayer, new Integer(9));
    layout = new ScalableAbsoluteLayout(resultLayer, 16, 12);
    resultLayer.setLayout(layout);

    result = new ScalableLabel("");
    result.setVisible(false);
    layout.addComponent(result, scoreboardLayout.getResultRect());

    goldenScore = new ScalableLabel("Golden Score");
    goldenScore.setVisible(false);
    layout.addComponent(goldenScore, scoreboardLayout.getGoldenScoreRect());

    goldenScoreApprove = new ScalableLabel("Golden Score");
    goldenScoreApprove.setVisible(false);
    layout.addComponent(goldenScoreApprove, scoreboardLayout.getGoldenScoreApproveRect());

    /*
     * Pending score layers
     */
    JPanel[] psLayer = new JPanel[3];
    pendingScores = new ScalableLabel[2][3];
    for (int i = 0; i < 3; i++) {
        psLayer[i] = new JPanel();
        psLayer[i].setOpaque(false);
        layeredPane.add(psLayer[i], new Integer(8 - i));
        layout = new ScalableAbsoluteLayout(psLayer[i], 16, 12);
        psLayer[i].setLayout(layout);

        for (int j = 0; j < 2; j++) {
            ScalableLabel label = new ScalableLabel("");
            label.setVisible(false);

            layout.addComponent(label, scoreboardLayout.getHolddownScoreRect(j, i));
            pendingScores[j][i] = label;
        }
    }

    /*
     * Holddown layer
     */
    JPanel hdLayer = new JPanel();
    hdLayer.setOpaque(false);
    layeredPane.add(hdLayer, new Integer(3));
    layout = new ScalableAbsoluteLayout(hdLayer, 16, 12);
    hdLayer.setLayout(layout);

    holddownTimer = new ScalableLabel(" ");
    holddownTimer.setVisible(false);
    layout.addComponent(holddownTimer, scoreboardLayout.getHolddownRect());

    /*
     * Bottom layer - background and core elements such as timer, player
     *                names and scores
     */
    bottomLayer = new JPanel();
    layeredPane.add(bottomLayer, new Integer(1));
    layout = new ScalableAbsoluteLayout(bottomLayer, 16, 12);
    bottomLayer.setLayout(layout);
    bottomLayer.setOpaque(false);

    timer = new ScalableLabel("5:00");
    player = new ScalableLabel[] { new ScalableLabel("Player 1"), new ScalableLabel("Player 2") };
    team = new ScalableLabel[] { new ScalableLabel("Team A"), new ScalableLabel("Team B") };

    if (scoreboardLayout instanceof IJFScoreboardLayout) {
        player[0].setHorizontalAlignment(JLabel.LEFT);
        player[1].setHorizontalAlignment(JLabel.LEFT);
        team[0].setHorizontalAlignment(JLabel.LEFT);
        team[1].setHorizontalAlignment(JLabel.LEFT);
    }

    layout.addComponent(timer, scoreboardLayout.getTimerRect());
    for (int i = 0; i < 2; i++) {
        layout.addComponent(player[i], scoreboardLayout.getPlayerLabelRect(i));
        layout.addComponent(team[i], scoreboardLayout.getTeamLabelRect(i));
    }

    scoreLabels = new ScalableLabel[2][2];
    score = new ScalableLabel[2][2];
    String[] iwyk = new String[] { "I", "W" };
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            Score s = Score.values()[j];
            scoreLabels[i][j] = new ScalableLabel(iwyk[j]);
            Rect rect = scoreboardLayout.getScoreLabelRect(i, s);
            if (rect != null)
                layout.addComponent(scoreLabels[i][j], rect);

            score[i][j] = new ScalableLabel("0");
            layout.addComponent(score[i][j], scoreboardLayout.getScoreRect(i, s));
        }
    }

    shido = new ScalableLabel[2][4];
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 4; j++) {
            shido[i][j] = new ScalableLabel("");
            shido[i][j].setVisible(false);
            // shidos get laid out dynamically in updateShidos
            //                layout.addComponent(shido[i][j], scoreboardLayout.getShidoRect(i, index, s, model));
        }
    }
    division = new ScalableLabel(" ");
    layout.addComponent(division, scoreboardLayout.getDivisionRect());

    // IJF Scoreboard has no borders on core components
    if (scoreboardLayout instanceof IJFScoreboardLayout) {
        // Remove borders
        for (Component c : bottomLayer.getComponents()) {
            if (c instanceof ScalableLabel) {
                ScalableLabel l = (ScalableLabel) c;
                l.setBorder(new EmptyBorder(0, 0, 0, 0));
            }
        }
    }

    /*
     * Background layer - purely for background colours as used by IJF
     *                    scoreboard
     */
    backgroundLayer = new JPanel();
    layeredPane.add(backgroundLayer, new Integer(0));
    layout = new ScalableAbsoluteLayout(backgroundLayer, 16, 12);
    backgroundLayer.setLayout(layout);
    backgroundLayer.setOpaque(false);

    // Add background last
    playerBackground = new ScalableLabel[2];
    for (int i = 0; i < 2; i++) {
        playerBackground[i] = new ScalableLabel("");
        playerBackground[i].setBorder(new EmptyBorder(0, 0, 0, 0));
        Rect r = scoreboardLayout.getPlayerBackgroundRect(i);
        if (r != null)
            layout.addComponent(playerBackground[i], r);
    }

    {
        Rect r = scoreboardLayout.getTimerBackgroundRect();
        timerBackground = new ScalableLabel("");
        timerBackground.setBorder(new EmptyBorder(0, 0, 0, 0));
        if (r != null)
            layout.addComponent(timerBackground, r);
    }
}

From source file:it.unibas.spicygui.vista.JLayeredPaneCorrespondences.java

private void createComponents() {
    this.pannelloPrincipale = new javax.swing.JPanel();
    this.pannelloPrincipale.setLayout(new java.awt.BorderLayout());
    this.glassPane = new GraphSceneGlassPane();
    this.intermediatePanel = new JPanel();
    this.intermediatePanel.setName(Costanti.INTERMEDIE);
    this.intermediatePanel.setLayout(new AbsoluteLayout());
    this.intermediatePanel.setBackground(Costanti.getIntermediateColor());

    this.scrollSource = new JScrollPane();
    this.scrollSource.setMinimumSize(new Dimension(200, getHeight()));
    this.splitChild = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scrollSource, intermediatePanel);
    //this.splitChild.setOneTouchExpandable(true);

    this.scrollTarget = new JScrollPane();
    this.scrollTarget.setMinimumSize(new Dimension(200, getHeight()));
    this.split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, this.getSplitChild(), scrollTarget);

    this.pannelloPrincipale.setOpaque(false);
    this.glassPane.setOpaque(false);
    this.setOpaque(false);

    OverlayLayout overlaylayout = new OverlayLayout(this);
    this.setLayout(overlaylayout);

    this.add(this.glassPane);
    this.add(this.pannelloPrincipale);
    this.pannelloPrincipale.add(getSplit());

    setSplitPane();/*from   w ww  . j  a  va 2 s.c  om*/
    initMouseListener();
}