Example usage for java.awt.event ComponentEvent getSource

List of usage examples for java.awt.event ComponentEvent getSource

Introduction

In this page you can find the example usage for java.awt.event ComponentEvent getSource.

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:Main.java

public static void main() {

    ComponentListener listener = new ComponentAdapter() {
        public void componentShown(ComponentEvent evt) {
            Component c = (Component) evt.getSource();
            System.out.println("Component is now visible");
        }/*w w  w  .jav  a  2s.  c o m*/

        public void componentHidden(ComponentEvent evt) {
            Component c = (Component) evt.getSource();
            System.out.println("Component is now hidden");
        }

        public void componentMoved(ComponentEvent evt) {
            Component c = (Component) evt.getSource();

            Point newLoc = c.getLocation();
            System.out.println("Get new location");
        }

        public void componentResized(ComponentEvent evt) {
            Component c = (Component) evt.getSource();

            Dimension newSize = c.getSize();
            System.out.println("Get new size");
        }
    };
    JFrame frame = new JFrame();
    frame.setSize(300, 300);
    frame.addComponentListener(listener);
    frame.setVisible(true);
}

From source file:Main.java

public static void setFontStyle(ComponentEvent event, int fontStyle) {
    Component c = (Component) event.getSource();
    setFontStyle(c, fontStyle);/*from w  ww. j a  va 2 s .c  o  m*/
}

From source file:Test.java

License:asdf

public ApplicationWindow() {
    this.setSize(300, 300);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    this.add(new JButton("asdf"));
    final Polygon myShape = getPolygon();
    this.addComponentListener(new ComponentAdapter() {
        @Override//from  w  w w .  j  a v  a 2  s. c o  m
        public void componentResized(ComponentEvent e) {
            setShape(myShape);
            ((JFrame) e.getSource()).setForeground(Color.red);
            ((JFrame) e.getSource()).setBackground(Color.red);
        }
    });

    this.setUndecorated(true);
}

From source file:Main.java

@Override
public void componentShown(ComponentEvent evt) {
    System.out.println(evt.getID() == ComponentEvent.COMPONENT_FIRST);
    ComponentEvent event = new ComponentEvent((Component) evt.getSource(), ComponentEvent.COMPONENT_MOVED);

}

From source file:net.pms.newgui.components.WindowProperties.java

@Override
public void componentResized(ComponentEvent e) {
    updateProperties((Window) e.getSource());
}

From source file:net.pms.newgui.components.WindowProperties.java

@Override
public void componentMoved(ComponentEvent e) {
    updateProperties((Window) e.getSource());
}

From source file:lejos.pc.charting.LogChartFrame.java

/** All the setup of components, etc. What's scary is Swing is a "lightweight" GUI framework...
 * @throws Exception/*from   w  w w .j  a  va  2s .  c  o m*/
 */
private void jbInit() throws Exception {
    this.setJMenuBar(menuBar);
    this.setSize(new Dimension(819, 613));
    this.setMinimumSize(new Dimension(819, 613));
    this.setTitle("NXT Charting Logger");
    this.setEnabled(true);
    // enforce minimum window size
    this.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            JFrame theFrame = (JFrame) e.getSource();
            Dimension d1 = theFrame.getMinimumSize();
            Dimension d2 = theFrame.getSize();
            boolean enforce = false;
            if (theFrame.getWidth() < d1.getWidth()) {
                d2.setSize(d1.getWidth(), d2.getHeight());
                enforce = true;
            }
            if (theFrame.getHeight() < d1.getHeight()) {
                d2.setSize(d2.getWidth(), d1.getHeight());
                enforce = true;
            }
            if (enforce)
                theFrame.setSize(d2);
        }
    });

    this.getContentPane().setLayout(gridBagLayout1);
    MenuActionListener menuItemActionListener = new MenuActionListener();
    MenuEventListener menuListener = new MenuEventListener();

    menu = new JMenu("Edit");
    menu.setMnemonic(KeyEvent.VK_E);
    menuBar.add(menu);
    menuItem = new JMenuItem("Copy Chart Image", KeyEvent.VK_I);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);
    menuItem = new JMenuItem("Copy Data Log", KeyEvent.VK_D);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);

    menu = new JMenu("View");
    menu.setMnemonic(KeyEvent.VK_V);
    menu.setActionCommand("VIEW_MENU");
    menu.addMenuListener(menuListener);
    menuBar.add(menu);
    menuItem = new JMenuItem("Expand Chart", KeyEvent.VK_F);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);
    menuItem = new JMenuItem("Chart in New Window", KeyEvent.VK_N);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);

    menu = new JMenu("Help");
    menu.setMnemonic(KeyEvent.VK_H);
    menuBar.add(menu);
    menuItem = new JMenuItem("Chart controls", KeyEvent.VK_C);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);
    menuItem = new JMenuItem("Generate sample data", KeyEvent.VK_G);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);
    menuItem = new JMenuItem("About", KeyEvent.VK_A);
    menuItem.addActionListener(menuItemActionListener);
    jTabbedPane1.setPreferredSize(new Dimension(621, 199));
    jTabbedPane1.setMinimumSize(new Dimension(621, 199));
    menu.add(menuItem);

    jButtonConnect.setText("Connect");
    jButtonConnect.setBounds(new Rectangle(25, 65, 115, 25));
    jButtonConnect.setToolTipText("Connect/disconnect toggle");
    jButtonConnect.setMnemonic('C');
    jButtonConnect.setSelected(true);
    jButtonConnect.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            jButtonConnect_actionPerformed(e);
        }
    });
    UIPanel.setSize(new Dimension(820, 200));
    UIPanel.setLayout(null);
    UIPanel.setPreferredSize(new Dimension(300, 200));
    UIPanel.setMinimumSize(new Dimension(300, 200));
    UIPanel.setBounds(new Rectangle(0, 350, 820, 200));
    UIPanel.setMaximumSize(new Dimension(300, 32767));
    connectionPanel.setBounds(new Rectangle(10, 10, 175, 100));
    connectionPanel.setBorder(BorderFactory.createTitledBorder("Connection"));
    connectionPanel.setLayout(null);
    connectionPanel.setFont(new Font("Tahoma", 0, 11));

    jLabel1logfilename.setText("Log File:");
    jLabel1logfilename.setBounds(new Rectangle(10, 125, 165, 20));
    jLabel1logfilename.setHorizontalTextPosition(SwingConstants.RIGHT);
    jLabel1logfilename.setHorizontalAlignment(SwingConstants.LEFT);
    jLabel1logfilename.setToolTipText("Specify the name of your log file here");

    jTextFieldNXTName.setBounds(new Rectangle(5, 40, 165, 20));
    jTextFieldNXTName.setToolTipText(
            "The name or Address of the NXT. Leave empty and the first one found will be used.");

    jTextFieldNXTName.requestFocus();

    jTextAreaStatus.setLineWrap(true);
    jTextAreaStatus.setFont(new Font("Tahoma", 0, 11));
    jTextAreaStatus.setWrapStyleWord(true);
    jTextAreaStatus.setBackground(SystemColor.window);

    dataLogTextArea.setLineWrap(false);
    dataLogTextArea.setFont(new Font("Tahoma", 0, 11));
    dataLogTextArea.setBackground(SystemColor.window);

    FQPathTextArea.setBounds(new Rectangle(5, 170, 185, 40));
    FQPathTextArea.setLineWrap(true);
    FQPathTextArea.setText(getCanonicalName(new File(".", "")));
    FQPathTextArea.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    FQPathTextArea.setRows(2);

    FQPathTextArea.setFont(new Font("Tahoma", 0, 9));
    FQPathTextArea.setOpaque(false);
    FQPathTextArea.setEditable(false);

    selectFolderButton.setText("Folder...");
    selectFolderButton.setBounds(new Rectangle(120, 125, 70, 20));
    selectFolderButton.setMargin(new Insets(1, 1, 1, 1));
    selectFolderButton.setFocusable(false);
    selectFolderButton.setMnemonic('F');
    selectFolderButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            selectFolderButton_actionPerformed(e);
        }
    });

    // domain display limits GUI
    chartOptionsPanel.setLayout(null);
    chartDomLimitsPanel.setBounds(new Rectangle(5, 35, 180, 135));
    chartDomLimitsPanel.setLayout(gridLayout1);
    chartDomLimitsPanel.setBorder(BorderFactory.createTitledBorder("Domain Display Limiting"));
    domainDisplayLimitSlider.setEnabled(false);
    domainDisplayLimitSlider.setMaximum(MAXDOMAIN_DATAPOINT_LIMIT);
    domainDisplayLimitSlider.setMinimum(MINDOMAIN_LIMIT);
    domainDisplayLimitSlider.setValue(MAXDOMAIN_DATAPOINT_LIMIT);
    domainDisplayLimitSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            domainDisplayLimitSlider_stateChanged(e);
        }
    });
    useTimeRadioButton.setText("By Time");
    useTimeRadioButton.setEnabled(false);
    useTimeRadioButton.setMnemonic('I');
    useTimeRadioButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            domainDisplayLimitRadioButton_actionPerformed(e);
        }
    });
    useDataPointsRadioButton.setText("By Data Points");
    ButtonGroup bg1 = new ButtonGroup();
    bg1.add(useTimeRadioButton);
    bg1.add(useDataPointsRadioButton);
    useDataPointsRadioButton.setSelected(true);
    useDataPointsRadioButton.setEnabled(false);
    useDataPointsRadioButton.setMnemonic('P');
    useDataPointsRadioButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            domainDisplayLimitRadioButton_actionPerformed(e);
        }
    });
    datasetLimitEnableCheckBox.setText("Enable");
    datasetLimitEnableCheckBox.setRolloverEnabled(true);
    datasetLimitEnableCheckBox.setMnemonic('A');
    datasetLimitEnableCheckBox.setToolTipText("Enable Domain Clipping");
    datasetLimitEnableCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            datasetLimitEnableCheckBox_actionPerformed(e);
        }
    });
    domainLimitLabel.setText(String.format("%1$,d datapoints", MAXDOMAIN_DATAPOINT_LIMIT).toString());
    domainLimitLabel.setEnabled(false);
    gridLayout1.setRows(5);
    gridLayout1.setColumns(1);

    jLabel1.setText("Chart Title:");
    jLabel1.setBounds(new Rectangle(200, 10, 85, 20));
    jLabel1.setPreferredSize(new Dimension(115, 14));
    jLabel2.setText("Range Axis 1 Label:");
    jLabel2.setBounds(new Rectangle(200, 35, 115, 20));
    jLabel2.setSize(new Dimension(115, 20));
    jLabel3.setText("Range Axis 2 Label:");
    jLabel3.setBounds(new Rectangle(200, 60, 115, 20));
    jLabel3.setSize(new Dimension(115, 20));
    jLabel4.setText("Range Axis 3 Label:");
    jLabel4.setBounds(new Rectangle(200, 85, 115, 20));
    jLabel4.setSize(new Dimension(115, 20));
    jLabel6.setText("Range Axis 4 Label:");
    jLabel6.setBounds(new Rectangle(200, 110, 115, 20));
    jLabel6.setSize(new Dimension(115, 20));
    titleLabelChangeNotifier notifier = new titleLabelChangeNotifier();
    chartTitleTextField.setBounds(new Rectangle(315, 10, 290, 20));
    chartTitleTextField.getDocument().addDocumentListener(notifier);
    axis1LabelTextField.setBounds(new Rectangle(315, 35, 290, 20));
    axis1LabelTextField.getDocument().addDocumentListener(notifier);
    axis2LabelTextField.setBounds(new Rectangle(315, 60, 290, 20));
    axis2LabelTextField.getDocument().addDocumentListener(notifier);
    axis3LabelTextField.setBounds(new Rectangle(315, 85, 290, 20));
    axis3LabelTextField.getDocument().addDocumentListener(notifier);
    axis4LabelTextField.setBounds(new Rectangle(315, 110, 290, 20));
    showCommentsCheckBox.setText("Show Comment Markers");
    showCommentsCheckBox.setBounds(new Rectangle(200, 140, 185, 25));
    showCommentsCheckBox.setToolTipText("Show/Hide any comment markers on the chart");
    showCommentsCheckBox.setRolloverEnabled(true);
    showCommentsCheckBox.setSelected(true);
    showCommentsCheckBox.setMnemonic('M');
    showCommentsCheckBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            customChartPanel.setCommentsVisible(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    scrollDomainCheckBox.setText("Scroll Domain");
    scrollDomainCheckBox.setBounds(new Rectangle(10, 5, 175, 20));
    scrollDomainCheckBox.setSize(new Dimension(175, 25));
    scrollDomainCheckBox.setSelected(true);
    scrollDomainCheckBox.setMnemonic('O');
    scrollDomainCheckBox.setToolTipText("Checked to scroll domain as new data is received");
    scrollDomainCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scrollDomainCheckBox_actionPerformed(e);
        }
    });
    axis4LabelTextField.getDocument().addDocumentListener(notifier);

    logFileTextField.setBounds(new Rectangle(10, 145, 180, 20));
    logFileTextField.setText("NXTData.txt");
    logFileTextField.setPreferredSize(new Dimension(180, 20));
    logFileTextField.setToolTipText("File name. Leave empty to not log to file.");
    statusScrollPane.setOpaque(false);
    dataLogScrollPane.setOpaque(false);

    customChartPanel.setMinimumSize(new Dimension(400, 300));
    customChartPanel.setPreferredSize(new Dimension(812, 400));

    jLabel5.setText("NXT Name/Address:");
    jLabel5.setBounds(new Rectangle(5, 20, 160, 20));
    jLabel5.setToolTipText(jTextFieldNXTName.getToolTipText());
    jLabel5.setHorizontalTextPosition(SwingConstants.RIGHT);
    jLabel5.setHorizontalAlignment(SwingConstants.LEFT);

    connectionPanel.add(jTextFieldNXTName, null);
    connectionPanel.add(jButtonConnect, null);
    connectionPanel.add(jLabel5, null);
    dataLogScrollPane.setViewportView(dataLogTextArea);
    jTabbedPane1.addTab("Data Log", dataLogScrollPane);
    statusScrollPane.setViewportView(jTextAreaStatus);
    jTabbedPane1.addTab("Status", statusScrollPane);
    jTabbedPane1.addTab("Chart", chartOptionsPanel);
    chartDomLimitsPanel.add(datasetLimitEnableCheckBox, null);
    chartDomLimitsPanel.add(useDataPointsRadioButton, null);
    chartDomLimitsPanel.add(useTimeRadioButton, null);
    chartDomLimitsPanel.add(domainDisplayLimitSlider, null);
    chartDomLimitsPanel.add(domainLimitLabel, null);
    chartOptionsPanel.add(scrollDomainCheckBox, null);
    chartOptionsPanel.add(showCommentsCheckBox, null);
    chartOptionsPanel.add(axis4LabelTextField, null);
    chartOptionsPanel.add(axis3LabelTextField, null);
    chartOptionsPanel.add(axis2LabelTextField, null);
    chartOptionsPanel.add(axis1LabelTextField, null);
    chartOptionsPanel.add(chartTitleTextField, null);
    chartOptionsPanel.add(jLabel6, null);
    chartOptionsPanel.add(jLabel4, null);
    chartOptionsPanel.add(jLabel3, null);
    chartOptionsPanel.add(jLabel2, null);
    chartOptionsPanel.add(jLabel1, null);
    chartOptionsPanel.add(chartDomLimitsPanel, null);

    tglbtnpauseplay = new JToggleButton("");
    tglbtnpauseplay.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (lpm == null)
                return;
            boolean doPause = false;
            if (e.getStateChange() == ItemEvent.SELECTED) {
                doPause = true;
            }
            lpm.setReaderPaused(doPause);
        }
    });
    //        tglbtnpauseplay.addChangeListener(new ChangeListener() {
    //           public void stateChanged(ChangeEvent e) {
    //              System.out.println(e.toString());
    //              //lpm.setReaderPaused(doPause)
    //           }
    //        });
    tglbtnpauseplay
            .setSelectedIcon(new ImageIcon(LogChartFrame.class.getResource("/lejos/pc/charting/play.png")));
    tglbtnpauseplay.setIcon(new ImageIcon(LogChartFrame.class.getResource("/lejos/pc/charting/pause.png")));
    tglbtnpauseplay.setBounds(571, 135, 30, 30);
    chartOptionsPanel.add(tglbtnpauseplay);

    jTabbedPane1.setToolTipTextAt(0, "The tab-delimited log of the data sent from the NXT");
    jTabbedPane1.setToolTipTextAt(1, "Status output");
    jTabbedPane1.setToolTipTextAt(2, "Chart options");
    jTabbedPane1.setMnemonicAt(0, KeyEvent.VK_D);
    jTabbedPane1.setMnemonicAt(1, KeyEvent.VK_S);
    jTabbedPane1.setMnemonicAt(2, KeyEvent.VK_T);
    this.getContentPane().add(customChartPanel, new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0,
            GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    this.getContentPane().add(UIPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(0, 0, 0, 0), -107, 0));

    this.getContentPane().add(jTabbedPane1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
            GridBagConstraints.NORTHEAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    UIPanel.add(connectionPanel, null);
    UIPanel.add(selectFolderButton, null);
    UIPanel.add(logFileTextField, null);
    UIPanel.add(jLabel1logfilename, null);
    UIPanel.add(FQPathTextArea, null);
    ActionListener taskPerformer = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            String theData = null;
            for (;;) {
                theData = LogChartFrame.this.logDataQueue.poll();
                if (theData == null)
                    break;
                try {
                    dataLogTextArea.getDocument().insertString(dataLogTextArea.getDocument().getLength(),
                            theData, null);
                } catch (BadLocationException e) {
                    System.out.print(
                            "BadLocationException in datalog textarea updater thread:" + e.toString() + "\n");
                }
            }
        }
    };
    this.updateLogTextAreaTimer = new Timer(1000, taskPerformer);
    this.updateLogTextAreaTimer.start();
}

From source file:jhplot.gui.GHPanel.java

public void componentResized(ComponentEvent e) {
    // System.out.println("Resized\n" + e.getSource());
    topPanel.setDefault(e.getSource());
    leftPanel.setDefault();/*from  w  w  w . j  a  v a  2  s .co m*/
    bottomPanel.setDefault();
    rightPanel.setDefault();

}

From source file:base.BasePlayer.Main.java

public void componentResized(ComponentEvent e) {
    if (e.getSource() == drawScroll) {
        if (Main.sidebarWidth != Main.upPanel.getDividerLocation() + 2) {
            if (samples * drawCanvas.drawVariables.sampleHeight < drawScroll.getViewport().getHeight()) {
                drawDimensions.setSize(drawScroll.getViewport().getWidth(),
                        drawScroll.getViewport().getSize().height);
                drawCanvas.setPreferredSize(drawDimensions);
                drawCanvas.resizeCanvas(drawScroll.getViewport().getWidth(),
                        drawScroll.getViewport().getHeight());

                if (drawCanvas.splits.size() > 0) {
                    for (int i = 0; i < drawCanvas.splits.size(); i++) {
                        drawCanvas.splits.get(i).updateReads = true;
                    }/*w w w  .j av  a  2 s  . com*/
                }
            }
            Draw.updatevars = true;
            drawCanvas.repaint();
        }
        Main.sidebarWidth = upPanel.getDividerLocation() + 4;
        chromDimensions.setSize(drawScroll.getViewport().getWidth() - upPanel.getDividerLocation(),
                splitPane.getDividerLocation());
        chromDraw.setPreferredSize(chromDimensions);
        chromDraw.updateExons = true;
        chromDraw.repaint();
        if (Main.samples == 0) {
            drawCanvas.resizeCanvas(drawScroll.getViewport().getWidth(), drawScroll.getViewport().getHeight());
        } else if (Main.drawCanvas.drawVariables.visiblesamples == Main.samples) {

            Main.drawCanvas.resizeCanvas(drawScroll.getViewport().getWidth(), Main.drawCanvas.getHeight());

            if (Main.drawCanvas.drawVariables.sampleHeight < Main.drawScroll.getViewport().getHeight()) {

                Main.drawCanvas.drawVariables.visiblesamples = (short) ((Main.drawScroll.getViewport()
                        .getHeight() / (double) Main.drawCanvas.drawVariables.sampleHeight) + 0.5);

            }
        }

        return;
    } else if (e.getSource() == chrompan) {
        if (Main.sidebarWidth != Main.upPanel.getDividerLocation() + 2) {
            if (samples * drawCanvas.drawVariables.sampleHeight < drawScroll.getViewport().getHeight()) {

                drawDimensions.setSize(drawScroll.getViewport().getWidth(),
                        drawScroll.getViewport().getSize().height);
                drawCanvas.setPreferredSize(drawDimensions);

                drawCanvas.resizeCanvas(drawScroll.getViewport().getWidth(),
                        drawScroll.getViewport().getHeight());
                if (drawCanvas.splits.size() > 0) {
                    for (int i = 0; i < drawCanvas.splits.size(); i++) {
                        drawCanvas.splits.get(i).updateReads = true;

                    }
                }

            }
            Main.bedCanvas.repaint();
            Main.controlDraw.repaint();
            Draw.updatevars = true;
            drawCanvas.repaint();

        }

        Main.sidebarWidth = upPanel.getDividerLocation() + 4;
        //   drawCanvas.drawWidth = drawScroll.getViewport().getWidth()-Main.sidebarWidth;
        chromDimensions.setSize(drawScroll.getViewport().getWidth() - upPanel.getDividerLocation(),
                splitPane.getDividerLocation());
        chromDraw.setPreferredSize(chromDimensions);
        chromDraw.updateExons = true;
        chromDraw.repaint();
        if (Main.drawCanvas.drawVariables.visiblesamples == Main.samples) {
            Main.drawCanvas.resizeCanvas(drawScroll.getViewport().getWidth(), Main.drawCanvas.getHeight());
            if (Main.drawCanvas.drawVariables.sampleHeight < Main.drawScroll.getViewport().getHeight()) {
                Main.drawCanvas.drawVariables.visiblesamples = (short) ((Main.drawScroll.getViewport()
                        .getHeight() / (double) Main.drawCanvas.drawVariables.sampleHeight) + 0.5);
                //TODO
            }
        } else {
            Main.drawCanvas.resizeCanvas(drawScroll.getViewport().getWidth(), Main.drawCanvas.getHeight());
        }

        return;

    }

    if (e.getComponent().getName() != null && e.getComponent().getName().contains("frame0")) {

        if (drawScroll.getViewport().getWidth() > 0) {
            drawDimensions.setSize(drawScroll.getViewport().getWidth(),
                    drawScroll.getViewport().getSize().height);
            drawCanvas.setPreferredSize(drawDimensions);

            chromDimensions.setSize(drawScroll.getViewport().getWidth() - Main.sidebarWidth - 1,
                    splitPane.getDividerLocation());

            chromDraw.setPreferredSize(chromDimensions);

            drawCanvas.resizeCanvas(drawScroll.getViewport().getWidth(), drawScroll.getViewport().getHeight());

            if (drawCanvas.splits.size() > 0) {
                for (int i = 0; i < drawCanvas.splits.size(); i++) {
                    drawCanvas.splits.get(i).updateReads = true;
                }
            }
            drawCanvas.repaint();
            return;
        }
    }
}

From source file:net.sourceforge.pmd.util.designer.Designer.java

private void createRuleXML() {
    CreateXMLRulePanel rulePanel = new CreateXMLRulePanel(xpathQueryArea, codeEditorPane);
    JFrame xmlframe = new JFrame("Create XML Rule");
    xmlframe.setContentPane(rulePanel);//from w  ww. j  av a 2s.c  o m
    xmlframe.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    xmlframe.setSize(new Dimension(600, 700));
    xmlframe.addComponentListener(new java.awt.event.ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            JFrame tmp = (JFrame) e.getSource();
            if (tmp.getWidth() < 600 || tmp.getHeight() < 700) {
                tmp.setSize(600, 700);
            }
        }
    });
    int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
    int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
    xmlframe.pack();
    xmlframe.setLocation((screenWidth - xmlframe.getWidth()) / 2, (screenHeight - xmlframe.getHeight()) / 2);
    xmlframe.setVisible(true);
}