Example usage for javax.swing JFrame setMinimumSize

List of usage examples for javax.swing JFrame setMinimumSize

Introduction

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

Prototype

public void setMinimumSize(Dimension minimumSize) 

Source Link

Document

Sets the minimum size of this window to a constant value.

Usage

From source file:Main.java

public static void main(String[] args) {
    final JFrame frame = new JFrame();
    frame.setMinimumSize(new Dimension(200, 200));
    frame.addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent evt) {
            Dimension size = frame.getSize();
            Dimension min = frame.getMinimumSize();
            if (size.getWidth() < min.getWidth()) {
                frame.setSize((int) min.getWidth(), (int) size.getHeight());
            }//from   w w  w .  jav a 2 s .c o m
            if (size.getHeight() < min.getHeight()) {
                frame.setSize((int) size.getWidth(), (int) min.getHeight());
            }
        }
    });
    frame.setSize(300, 300);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Hello World");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setMinimumSize(new Dimension(100, 100));
    frame.setVisible(true);//w  w w.  j  a v  a2  s  .c  o  m
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new TabView());
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.setMinimumSize(new Dimension(800, 450));
    frame.pack();//from w ww.  ja  va 2 s .c om
    frame.setVisible(true);
}

From source file:fsart.diffTools.gui.DiffToolsGui.java

public static void main(String[] args) {
    //Create and set up the window.
    JFrame frame = new JFrame("DiffTools");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    log.debug("Demarrage de l'application");

    DiffToolsMainPanel gui = new DiffToolsMainPanel();

    frame.add(gui.getPanel());/*from  w w w  .  j ava  2s. c o  m*/
    frame.setMinimumSize(gui.getPanel().getMinimumSize());
    frame.pack();
    //frame.setMinimumSize(gui.getPanel().getMinimumSize());
    frame.setLocationRelativeTo(frame.getParent());
    frame.setVisible(true);
    //System.exit(0);
}

From source file:com.googlecode.sarasvati.visual.jung.JungVisualizer.java

@SuppressWarnings("serial")
public static void main(String[] args) throws Exception {
    TestSetup.init();//from w  w w .  j a v a2s .  c o m

    Session session = TestSetup.openSession();
    HibEngine engine = new HibEngine(session);

    JFrame frame = new JFrame("Workflow Visualizer");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setMinimumSize(new Dimension(800, 600));

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    frame.getContentPane().add(splitPane);

    DefaultListModel listModel = new DefaultListModel();
    for (Graph g : engine.getRepository().getGraphs()) {
        listModel.addElement(g);
    }

    ListCellRenderer cellRenderer = new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

            Graph g = (Graph) value;

            setText(g.getName() + "." + g.getVersion() + "  ");
            return this;
        }
    };

    final JList graphList = new JList(listModel);
    graphList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    graphList.setCellRenderer(cellRenderer);

    JScrollPane listScrollPane = new JScrollPane(graphList);
    listScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    listScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    splitPane.add(listScrollPane);

    //TreeLayout<NodeRef, Arc> layout = new TreeLayout<NodeRef, Arc>();

    DirectedSparseMultigraph<Node, Arc> graph = new DirectedSparseMultigraph<Node, Arc>();

    //final SpringLayout2<HibNodeRef, HibArc> layout = new SpringLayout2<HibNodeRef, HibArc>(graph);
    //final KKLayout<HibNodeRef, HibArc> layout = new KKLayout<HibNodeRef, HibArc>(graph);
    final TreeLayout layout = new TreeLayout(graph);
    final BasicVisualizationServer<Node, Arc> vs = new BasicVisualizationServer<Node, Arc>(layout);
    //vs.getRenderContext().setVertexLabelTransformer( new NodeLabeller() );
    //vs.getRenderContext().setEdgeLabelTransformer( new ArcLabeller() );
    vs.getRenderContext().setVertexShapeTransformer(new NodeShapeTransformer());
    vs.getRenderContext().setVertexFillPaintTransformer(new NodeColorTransformer());
    vs.getRenderContext().setLabelOffset(5);
    vs.getRenderContext().setVertexIconTransformer(new Transformer<Node, Icon>() {
        @Override
        public Icon transform(Node node) {
            return "task".equals(node.getType()) ? new TaskIcon(node) : null;
        }
    });

    Transformer<Arc, Paint> edgeColorTrans = new Transformer<Arc, Paint>() {
        private Color darkRed = new Color(128, 0, 0);

        @Override
        public Paint transform(Arc arc) {
            return "reject".equals(arc.getName()) ? darkRed : Color.black;
        }
    };

    vs.getRenderContext().setEdgeDrawPaintTransformer(edgeColorTrans);
    vs.getRenderContext().setArrowDrawPaintTransformer(edgeColorTrans);

    final JScrollPane scrollPane = new JScrollPane(vs);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);

    splitPane.add(scrollPane);
    scrollPane.setBackground(Color.white);

    graphList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }

            final Graph g = (Graph) graphList.getSelectedValue();

            if ((g == null && currentGraph == null) || (g != null && g.equals(currentGraph))) {
                return;
            }

            currentGraph = g;

            DirectedSparseMultigraph<Node, Arc> jungGraph = new DirectedSparseMultigraph<Node, Arc>();

            for (Node ref : currentGraph.getNodes()) {
                jungGraph.addVertex(ref);
            }

            for (Arc arc : currentGraph.getArcs()) {
                jungGraph.addEdge(arc, arc.getStartNode(), arc.getEndNode());
            }

            GraphTree graphTree = new GraphTree(g);
            layout.setGraph(jungGraph);
            layout.setInitializer(new NodeLocationTransformer(graphTree));
            scrollPane.repaint();
        }
    });

    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    JFrame frame = new JFrame();

    JButton btn = new JButton("Test");

    JPanel panel = new JPanel();
    panel.add(btn);//from  w  w  w  .  j a v  a2s  .  c om

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.add("Tab1", panel);

    frame.add(tabbedPane, BorderLayout.CENTER);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setMinimumSize(new Dimension(300, 300));
    frame.setVisible(true);
}

From source file:Main.java

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

    JPanel gui = new JPanel(new BorderLayout(5, 5));

    JPanel plafComponents = new JPanel(new FlowLayout(FlowLayout.RIGHT, 3, 3));
    plafComponents.setBorder(new TitledBorder("FlowLayout(FlowLayout.RIGHT, 3,3)"));

    UIManager.LookAndFeelInfo[] plafInfos = UIManager.getInstalledLookAndFeels();
    String[] plafNames = new String[plafInfos.length];
    for (int ii = 0; ii < plafInfos.length; ii++) {
        plafNames[ii] = plafInfos[ii].getName();
    }//from   w  ww  . j a  v  a 2s . c  om
    JComboBox plafChooser = new JComboBox(plafNames);
    plafComponents.add(plafChooser);

    JCheckBox pack = new JCheckBox("Pack on PLAF change", true);
    plafComponents.add(pack);

    plafChooser.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            int index = plafChooser.getSelectedIndex();
            try {
                UIManager.setLookAndFeel(plafInfos[index].getClassName());
                SwingUtilities.updateComponentTreeUI(frame);
                if (pack.isSelected()) {
                    frame.pack();
                    frame.setMinimumSize(frame.getSize());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    gui.add(plafComponents, BorderLayout.NORTH);

    JPanel dynamicLabels = new JPanel(new BorderLayout(4, 4));
    dynamicLabels.setBorder(new TitledBorder("BorderLayout(4,4)"));
    gui.add(dynamicLabels, BorderLayout.WEST);

    final JPanel labels = new JPanel(new GridLayout(0, 2, 3, 3));
    labels.setBorder(new TitledBorder("GridLayout(0,2,3,3)"));

    JButton addNew = new JButton("Add Another Label");
    dynamicLabels.add(addNew, BorderLayout.NORTH);
    addNew.addActionListener(new ActionListener() {

        private int labelCount = 0;

        public void actionPerformed(ActionEvent ae) {
            labels.add(new JLabel("Label " + ++labelCount));
            frame.validate();
        }
    });

    dynamicLabels.add(new JScrollPane(labels), BorderLayout.CENTER);

    String[] header = { "Name", "Value" };
    String[] a = new String[0];
    String[] names = System.getProperties().stringPropertyNames().toArray(a);
    String[][] data = new String[names.length][2];
    for (int ii = 0; ii < names.length; ii++) {
        data[ii][0] = names[ii];
        data[ii][1] = System.getProperty(names[ii]);
    }
    DefaultTableModel model = new DefaultTableModel(data, header);
    JTable table = new JTable(model);

    JScrollPane tableScroll = new JScrollPane(table);
    Dimension tablePreferred = tableScroll.getPreferredSize();
    tableScroll.setPreferredSize(new Dimension(tablePreferred.width, tablePreferred.height / 3));

    JPanel imagePanel = new JPanel(new GridBagLayout());
    JLabel imageLabel = new JLabel("test");
    imagePanel.add(imageLabel, null);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tableScroll, new JScrollPane(imagePanel));
    gui.add(splitPane, BorderLayout.CENTER);

    frame.setContentPane(gui);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

/**
 * /*from  w  w  w.  j  a va  2 s  .c om*/
 * @param component
 */
public static void setMiniSize(JFrame component) {
    Dimension size = new Dimension();

    size.height = (int) (Toolkit.getDefaultToolkit().getScreenSize().height / 4);
    size.width = (int) (Toolkit.getDefaultToolkit().getScreenSize().width / 4);

    component.setMinimumSize(size);
}

From source file:Main.java

public Main() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new MyPanel());
    frame.pack();/*from w w w . ja v a2s  . co m*/
    frame.setMinimumSize(frame.getPreferredSize());
    frame.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());
    }//from   www.  j a va2 s .co  m

    // 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.");
    }
}