Example usage for javax.swing JFrame setPreferredSize

List of usage examples for javax.swing JFrame setPreferredSize

Introduction

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

Prototype

public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component to a constant value.

Usage

From source file:Main.java

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

    JTextPane pane = new JTextPane();
    pane.setEditorKit(new CustomEditorKit());
    pane.setText("Underline With Different Color");

    StyledDocument doc = (StyledDocument) pane.getDocument();
    MutableAttributeSet attrs = new SimpleAttributeSet();
    attrs.addAttribute("Underline-Color", Color.red);
    doc.setCharacterAttributes(0, doc.getLength() - 1, attrs, true);

    JScrollPane sp = new JScrollPane(pane);
    frame.setContentPane(sp);//from   www.j  a va 2 s  .c  om
    frame.setPreferredSize(new Dimension(400, 300));
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:gda.gui.BatonPanel.java

/**
 * Auto-generated main method to display this JPanel inside a new JFrame.
 * /*w  w  w  .j  av  a  2s  . c o  m*/
 * @param args
 */
public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.pack();
    frame.setSize(792, 419);
    frame.setPreferredSize(new java.awt.Dimension(792, 419));
    frame.setVisible(true);
    {
        batonPanel_IL = new BatonPanel();
        frame.getContentPane().add(batonPanel_IL, BorderLayout.CENTER);
        BorderLayout batonPanel_ILLayout = new BorderLayout();
        batonPanel_IL.setLayout(batonPanel_ILLayout);
    }
}

From source file:ar.com.zauber.commons.spring.mail.SwingMailSender.java

/** @see SimpleMailMessage[]) */
public final void send(final SimpleMailMessage[] simpleMessages) throws MailException {
    final JTextArea area = new JTextArea(AbstractMailSender.toString(simpleMessages));
    area.setLineWrap(true);/*ww  w .j a v  a2 s.c  o m*/
    final JFrame frame = new JFrame("email sent");
    frame.getContentPane().add(new JScrollPane(area, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
    final int frameWidth = 640;
    final int frameHeight = 480;
    frame.setPreferredSize(new Dimension(frameWidth, frameHeight));
    frame.pack();
    frame.setVisible(true);
}

From source file:llc.rockford.webcast.EC2Driver.java

private void createAndShowGUI() {
    // Set the look and feel.
    initLookAndFeel();/*from  w w w  .  java  2  s .co m*/

    // Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

    // Create and set up the window.
    JFrame frame = new JFrame("Webcast Utility");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setPreferredSize(new Dimension(300, 400));
    java.net.URL url = ClassLoader.getSystemResource("llc/rockford/webcast/resources/internet.png");
    Toolkit kit = Toolkit.getDefaultToolkit();
    Image img = kit.createImage(url);
    frame.setIconImage(img);
    Component contents = createComponents();
    frame.getContentPane().add(contents, BorderLayout.CENTER);

    // Display the window.
    frame.pack();
    frame.setVisible(true);

}

From source file:scheduler.benchmarker.manager.CreateCombinedSplineChart.java

private void createSubChart(ChartPanel chart) {
    JFrame frameGraph = new JFrame();
    frameGraph.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frameGraph.setForeground(new Color(76, 76, 76));
    frameGraph.setBackground(new Color(246, 244, 242));

    Dimension window = Toolkit.getDefaultToolkit().getScreenSize();
    if (window.width < 1074 && window.height < 800)
        frameGraph.setPreferredSize(new Dimension(window.width, window.height));
    else//w  w  w .ja  v  a  2s  .c  o m
        frameGraph.setPreferredSize(new Dimension(1074, 800));

    frameGraph.setLocation((window.width - frameGraph.getPreferredSize().width) / 2,
            (window.height - frameGraph.getPreferredSize().height) / 2);
    frameGraph.setResizable(true);
    frameGraph.add(chart);
    frameGraph.pack();
    frameGraph.setVisible(true);
}

From source file:scheduler.benchmarker.manager.CreateSimpleSplineChart.java

private void createSubChart(ChartPanel chart) {
    JFrame frameGraph = new JFrame();//new JFrame("FINAL RULES ARRANGEMENT");
    frameGraph.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frameGraph.setForeground(new Color(76, 76, 76));
    frameGraph.setBackground(new Color(246, 244, 242));

    Dimension window = Toolkit.getDefaultToolkit().getScreenSize();
    if (window.width < 1074 && window.height < 800)
        frameGraph.setPreferredSize(new Dimension(window.width, window.height));
    else//w w  w .j  ava 2s .  c  o  m
        frameGraph.setPreferredSize(new Dimension(1074, 800));

    frameGraph.setLocation((window.width - frameGraph.getPreferredSize().width) / 2,
            (window.height - frameGraph.getPreferredSize().height) / 2);
    frameGraph.setResizable(true);
    frameGraph.add(chart);
    frameGraph.pack();
    frameGraph.setVisible(true);
}

From source file:br.com.ant.system.util.ChartUtil.java

public void createTempoTotalExecucao(Set<EstatisticaColetor> estatisticas) {

    // Create a simple XY chart
    XYSeries series = new XYSeries("Formiga");

    JFrame frame = new JFrame();

    for (EstatisticaColetor e : estatisticas) {
        series.add(e.getId(), e.getTempoExecucao());
    }//  www  .j a  v a  2s  .com

    // Add the series to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart("Tempo total de Execuo", "Execuo", "Tempo (ms)",
            dataset, PlotOrientation.VERTICAL, true, true, false);
    frame.getContentPane().add(new ChartPanel(chart));

    frame.setPreferredSize(new Dimension(600, 600));
    frame.setMinimumSize(new Dimension(600, 600));
    frame.setMaximumSize(new Dimension(600, 600));
    frame.setVisible(true);

    try {
        ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");
    }
}

From source file:courseapplication.CourseApplication1.java

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
    double[] xValues = data.getxValues();
    double[] yValues = data.getyValues();
    double step = 0.0001;
    double[] xValuesForGraph = prepareArray(xValues, step);
    double[] polinom = new double[xValuesForGraph.length];
    double[] lagr = new double[xValuesForGraph.length];
    XYSeries seriesFunction = new XYSeries("Function values");
    XYSeries seriesLagranje = new XYSeries("Lagranje values");
    XYSeries seriesPolinom = new XYSeries("Polinom values");
    double[] yValuesForGraph = new double[xValuesForGraph.length];

    for (int i = 0; i < yValuesForGraph.length; i++) {
        yValuesForGraph[i] = data.function(function, (xValuesForGraph[i]));
    }/*from w  ww.ja  va2s . c o m*/

    for (int i = 0; i < yValuesForGraph.length; i++) {
        polinom[i] = interpolation.polinomInterpolation(polinomResult, xValuesForGraph[i]);
        lagr[i] = interpolation.lagranjeInterpolation(xValues, yValues, xValuesForGraph[i]);
    }

    for (int i = 0; i < xValuesForGraph.length; i++) {
        seriesFunction.add(xValuesForGraph[i], yValuesForGraph[i]);
        seriesLagranje.add(xValuesForGraph[i], lagr[i]);
        seriesPolinom.add(xValuesForGraph[i], polinom[i]);

    }

    XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(seriesFunction);
    data.addSeries(seriesLagranje);
    data.addSeries(seriesPolinom);

    // XYDataset data = new XYSeriesCollection(seriesFunction);

    JFreeChart chart = ChartFactory.createXYLineChart("Function values and approximation functions", "X",
            "F(x)", data, PlotOrientation.VERTICAL, true, true, true);
    JFrame frameForGraphic = new JFrame("Graphic");
    XYPlot plot = chart.getXYPlot();
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.GREEN);
    renderer.setSeriesPaint(1, Color.BLUE);
    renderer.setSeriesPaint(2, Color.PINK);
    frameForGraphic.getContentPane().add(new ChartPanel(chart));
    frameForGraphic.show();
    frameForGraphic.setPreferredSize(new Dimension(800, 600));
    frameForGraphic.setLocationRelativeTo(null);
    frameForGraphic.pack();
}

From source file:is.iclt.jcorpald.CorpaldView.java

public void createAndShowGUI() {
    CorpaldSettings settings = CorpaldSettings.getInstance();

    //Create and set up the window.
    JFrame frame = new JFrame(settings.getProperty("corpus.acronym") + " "
            + settings.getProperty("corpus.version") + " - " + settings.getProperty("corpus.longname"));
    frame.setIconImage((new ImageIcon("icons/corpald.png")).getImage());

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // frame.setBounds(50, 50, 700, 450);
    frame.setPreferredSize(new Dimension(750, 720));

    // Create the panel that has the query and the result        
    JPanel panMainArea = new JPanel(new BorderLayout());
    JPanel panQuery = new JPanel(new BorderLayout());

    txtQuery = new JHighlightPane();
    txtQuery.addKeyListener(this);

    txtQuery.setFont(new Font("Monospaced", Font.BOLD, 16));
    this.updateHighlighting();
    txtQuery.setPreferredSize(new Dimension(700, 150));

    panQuery.add(labQuery, BorderLayout.NORTH);
    panQuery.add(new JScrollPane(txtQuery, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS), BorderLayout.CENTER);
    panQuery.setBorder(new EmptyBorder(0, 10, 10, 10));

    String welcomeMessage = "";
    try {//from  w  ww.  ja va2s .c  om
        welcomeMessage = FileUtils.readFileToString(new File(settings.getProperty("corpus.welcome")), "utf-8");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    JPanel panResult = new JPanel(new BorderLayout());
    txtResult = new JTextArea(welcomeMessage);

    txtResult.setEditable(false);
    txtResult.setFont(new Font("Monospaced", Font.BOLD, 14));

    JScrollPane scrResult = new JScrollPane(txtResult, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrResult.setPreferredSize(new Dimension(700, 400));
    panResult.add(new JLabel("Result:"), BorderLayout.NORTH);
    panResult.add(scrResult, BorderLayout.CENTER);
    panResult.setBorder(new EmptyBorder(0, 10, 0, 10));

    panMainArea.add(panQuery, BorderLayout.NORTH);
    panMainArea.add(panResult, BorderLayout.CENTER);

    // Create panel at top with buttons
    JPanel panToolbar = new JPanel(new FlowLayout(FlowLayout.CENTER));

    // New, Open, Save
    // New
    ImageIcon icoNewQuery = new ImageIcon("icons/page_white.png");
    butNewQuery = new JButton(icoNewQuery);
    butNewQuery.addActionListener(this);
    butNewQuery.setPreferredSize(new Dimension(26, 26));
    butNewQuery.setToolTipText("Create a new empty query");
    panToolbar.add(butNewQuery);
    // Open
    ImageIcon icoOpenQuery = new ImageIcon("icons/folder.png");
    butOpenQuery = new JButton(icoOpenQuery);
    butOpenQuery.addActionListener(this);
    butOpenQuery.setPreferredSize(new Dimension(26, 26));
    butOpenQuery.setToolTipText("Open a query file");
    panToolbar.add(butOpenQuery);
    // Save
    ImageIcon icoSaveQuery = new ImageIcon("icons/page_save.png");
    butSaveQuery = new JButton(icoSaveQuery);
    butSaveQuery.addActionListener(this);
    butSaveQuery.setPreferredSize(new Dimension(26, 26));
    butSaveQuery.setToolTipText("Save current query");
    panToolbar.add(butSaveQuery);
    // Save as
    ImageIcon icoSaveQueryAs = new ImageIcon("icons/page_save_as.png");
    butSaveQueryAs = new JButton(icoSaveQueryAs);
    butSaveQueryAs.addActionListener(this);
    butSaveQueryAs.setPreferredSize(new Dimension(26, 26));
    butSaveQueryAs.setToolTipText("Save current query under a new file name");
    panToolbar.add(butSaveQueryAs);

    // Open definitions file
    ImageIcon icoOpenDef = new ImageIcon("icons/folder_table.png");
    butOpenDef = new JButton(icoOpenDef);
    butOpenDef.addActionListener(this);
    butOpenDef.setPreferredSize(new Dimension(26, 26));
    butOpenDef.setToolTipText("Select a new definitions file");
    panToolbar.add(butOpenDef);

    // Run Query button
    ImageIcon icoRunQuery = new ImageIcon("icons/control_play_blue.png");
    butRunQuery = new JButton("Run Query", icoRunQuery);
    butRunQuery.setPreferredSize(new Dimension(130, 26));
    butRunQuery.addActionListener(this);
    butRunQuery.setToolTipText("Run the current query using CorpusSearch");
    panToolbar.add(butRunQuery);

    // TextField for root node label
    JLabel labRootNode = new JLabel("Root:");
    panToolbar.add(labRootNode);
    txtRootNode = new JTextField("", 12);
    txtRootNode.setPreferredSize(new Dimension(50, 26));
    txtRootNode.addKeyListener(this);
    txtRootNode.setMargin(new Insets(3, 3, 3, 3));
    txtRootNode.setToolTipText("<html>Search within instances of a particular type of node,<br/>"
            + "such as IP-*, IP-SUB, NP-*, etc. $ROOT matches<br/>"
            + "the root node of every tree in the corpus.</html>");
    panToolbar.add(txtRootNode);

    chkNodesOnly = new JCheckBox("Nodes only");
    chkNodesOnly.addItemListener(this);
    chkNodesOnly.setToolTipText("<html>If checked, CorpusSearch prints out only the nodes that<br/>"
            + "contain the structure described in \"Query\". If not checked,<br/>"
            + "CorpusSearch prints out the entire sentence that contains the<br/>"
            + "structure described in \"Query\".</html>");
    panToolbar.add(chkNodesOnly);

    chkRemoveNodes = new JCheckBox("Remove nodes");
    chkRemoveNodes.addItemListener(this);
    chkRemoveNodes.setToolTipText("<html>Remove subtrees whose root is of the same syntactic category<br/>"
            + "as the node boundary embedded within a instance of that node<br/>"
            + "boundary. \"Remove nodes\" thus removes recursive structure.</html>");
    panToolbar.add(chkRemoveNodes);

    // Create panel at top with buttons
    JPanel panBottombar = new JPanel(new FlowLayout(FlowLayout.CENTER));
    // panBottombar.setBorder(new EmptyBorder(0, 0, 10, 5));
    ImageIcon icoOpenFolder = new ImageIcon("icons/folder.png");
    butOpenFolder = new JButton("Show result in folder", icoOpenFolder);
    butOpenFolder.setEnabled(false);
    butOpenFolder.addActionListener(this);
    panBottombar.add(butOpenFolder);

    ImageIcon icoTextEditor = new ImageIcon("icons/page_white_go.png");
    butTextEditor = new JButton("Open result in text editor", icoTextEditor);
    butTextEditor.setEnabled(false);
    butTextEditor.addActionListener(this);
    panBottombar.add(butTextEditor);

    ImageIcon icoCopyResults = new ImageIcon("icons/page_copy.png");
    butCopyResults = new JButton("Copy result to clipboard", icoCopyResults);
    butCopyResults.setEnabled(false);
    butCopyResults.addActionListener(this);
    panBottombar.add(butCopyResults);

    // Add stuff to top level content pane                
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(panToolbar, BorderLayout.NORTH);
    frame.getContentPane().add(panMainArea, BorderLayout.CENTER);
    frame.getContentPane().add(panBottombar, BorderLayout.SOUTH);

    this.configureFileFilters();

    //Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:au.org.ala.delta.editor.DeltaEditor.java

@Override
protected void startup() {

    _actionMap = getContext().getActionMap(this);

    JFrame frame = getMainFrame();
    frame.setPreferredSize(new Dimension(800, 600));

    frame.setIconImages(IconHelper.getBlueIconList());

    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    addExitListener(new ExitListener() {

        @Override// www.  ja  v  a2 s. c  o  m
        public void willExit(EventObject event) {
        }

        @Override
        public boolean canExit(EventObject event) {

            boolean canClose = closeAll();

            return canClose;
        }
    });

    _helpController = new HelpController("help/delta_editor/DeltaEditor");
    _dataSetRepository = new SlotFileRepository();

    _statusBar = new StatusBar();
    // Hiding the status bar as it doesn't really convey much useful information and takes up screen space.
    //getMainView().setStatusBar(_statusBar);

    getMainView().setMenuBar(buildMenus());

    _helpController.enableHelpKey(frame);

    createDesktop();
    show(_desktop);

}