List of usage examples for javax.swing JFrame setLayout
public void setLayout(LayoutManager manager)
LayoutManager
. From source file:Main.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame(); frame.setTitle("JLabel Test"); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ImageIcon imageIcon = new ImageIcon("yourFile.gif"); JLabel label = new JLabel("Mixed", imageIcon, SwingConstants.RIGHT); frame.add(label);// ww w . ja va2 s . c o m frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JProgressBar progressBar = new JProgressBar(); JButton button = new JButton("Start"); JFrame f = new JFrame(); f.setLayout(new FlowLayout()); f.add(progressBar);/* w w w. ja v a2 s . c o m*/ f.add(button); ActionListener updateProBar = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { int val = progressBar.getValue(); if (val >= 100) { // timer.stop(); button.setText("End"); return; } progressBar.setValue(++val); } }; Timer timer = new Timer(50, updateProBar); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (timer.isRunning()) { timer.stop(); button.setText("Start"); } else if (button.getText() != "End") { timer.start(); button.setText("Stop"); } } }); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JFrame parent1 = new JFrame("Parent Frame 1"); parent1.setLayout(new FlowLayout()); parent1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Application modal dialog"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JDialog dialog = new JDialog(parent1, "Application-Modal Dialog", Dialog.ModalityType.APPLICATION_MODAL); dialog.setBounds(200, 150, 200, 150); dialog.setVisible(true);//from w w w .jav a2 s . c o m } }); parent1.add(button); parent1.setBounds(100, 100, 200, 150); parent1.setVisible(true); JFrame parent2 = new JFrame("Parent Frame 2"); parent2.setBounds(500, 100, 200, 150); parent2.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { String[] mainData = { "-Select-", "Sel 1", "Sel 2", "Sel 3" }; String[] subData1 = { "Sub Sel 11", "Sub Sel 12", "Sub Sel 13" }; String[] subData2 = { "Sub Sel 21", "Sub Sel 22", "Sub Sel 23" }; String[] subData3 = { "Sub Sel 31", "Sub Sel 32", "Sub Sel 33" }; DefaultComboBoxModel boxModel = new DefaultComboBoxModel(); JComboBox box1 = new JComboBox(mainData), box2 = new JComboBox(); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.add(box1);/*from w w w . j a v a2 s . c o m*/ frame.add(box2); box2.setVisible(false); box2.setModel(boxModel); frame.setBounds(200, 200, 500, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); box1.addItemListener(e -> { box2.setVisible(true); boxModel.removeAllElements(); if (box1.getSelectedIndex() == 0) { box2.setVisible(false); } else if (box1.getSelectedIndex() == 1) { for (String s : subData1) { boxModel.addElement(s); } } else if (box1.getSelectedIndex() == 2) { for (String s : subData2) { boxModel.addElement(s); } } else if (box1.getSelectedIndex() == 3) { for (String s : subData3) { boxModel.addElement(s); } } }); }
From source file:Main.java
public static void main(String[] args) { final Timer timer; final JProgressBar progressBar = new JProgressBar(); final JButton button = new JButton("Start"); JFrame f = new JFrame(); f.setLayout(new FlowLayout()); f.add(progressBar);/*from w ww . j a v a 2 s .c o m*/ f.add(button); ActionListener updateProBar = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { int val = progressBar.getValue(); if (val >= 100) { // timer.stop(); button.setText("End"); return; } progressBar.setValue(++val); } }; timer = new Timer(50, updateProBar); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (timer.isRunning()) { timer.stop(); button.setText("Start"); } else if (button.getText() != "End") { timer.start(); button.setText("Stop"); } } }); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setResizable(false); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:SimpleDnD.java
public static void main(String[] args) { JTextField field = new JTextField(10); JButton button = new JButton("Button"); JFrame f = new JFrame(); f.setTitle("Simple Drag & Drop"); f.setLayout(new FlowLayout()); f.add(button);// w w w . ja v a2 s. c o m f.add(field); field.setDragEnabled(true); button.setTransferHandler(new TransferHandler("text")); f.setSize(330, 150); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { Vector<Double> doubleVector = new Vector<Double>(); Vector<Integer> integerVector = new Vector<Integer>(); Vector<Boolean> booleanVector = new Vector<Boolean>(); Vector<Icon> iconVector = new Vector<Icon>(); Icon icon1 = ((UIManager.getIcon("OptionPane.errorIcon"))); Icon icon2 = (UIManager.getIcon("OptionPane.informationIcon")); Icon icon3 = (UIManager.getIcon("OptionPane.warningIcon")); Icon icon4 = (UIManager.getIcon("OptionPane.questionIcon")); doubleVector.addElement(1.001);// www .j av a 2 s. co m doubleVector.addElement(10.00); doubleVector.addElement(0.95); doubleVector.addElement(4.2); JComboBox comboBoxDouble = new JComboBox(doubleVector); integerVector.addElement(1); integerVector.addElement(2); integerVector.addElement(3); integerVector.addElement(4); JComboBox comboBoxInteger = new JComboBox(integerVector); booleanVector.add(Boolean.TRUE); booleanVector.add(Boolean.FALSE); JComboBox comboBoxBoolean = new JComboBox(booleanVector); iconVector.addElement(icon1); iconVector.addElement(icon2); iconVector.addElement(icon3); iconVector.addElement(icon4); JComboBox comboBoxIcon = new JComboBox(iconVector); JFrame frame = new JFrame(); frame.setLayout(new GridLayout(2, 2, 5, 5)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(comboBoxDouble); frame.add(comboBoxInteger); frame.add(comboBoxBoolean); frame.add(comboBoxIcon); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl); frame.add(new JButton("1")); frame.add(new JButton("2")); gbl.layoutContainer(frame);//from w ww .j a v a2 s .c om gbl.columnWeights = new double[] { 0.0f, 1.0f, 2.0f }; gbl.rowWeights = new double[] { 0.0f, 1.0f }; frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { NumberFormat format = NumberFormat.getNumberInstance(); format.setMaximumFractionDigits(2);//from w ww . j av a 2s .co m format.setMinimumFractionDigits(2); format.setParseIntegerOnly(true); format.setRoundingMode(RoundingMode.HALF_UP); NumberFormatter formatter = new NumberFormatter(format); formatter.setMaximum(1000); formatter.setMinimum(0.0); formatter.setAllowsInvalid(false); // formatter.setOverwriteMode(false); JFormattedTextField tf = new JFormattedTextField(formatter); tf.setColumns(10); tf.setValue(123456789.99); JFormattedTextField tf1 = new JFormattedTextField(formatter); tf1.setValue(1234567890.99); JFormattedTextField tf2 = new JFormattedTextField(formatter); tf2.setValue(1111.1111); JFormattedTextField tf3 = new JFormattedTextField(formatter); tf3.setValue(-1111.1111); JFormattedTextField tf4 = new JFormattedTextField(formatter); tf4.setValue(-56); JFrame frame = new JFrame("Test"); frame.setLayout(new GridLayout(5, 0)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(tf); frame.add(tf1); frame.add(tf2); frame.add(tf3); frame.add(tf4); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JEditorPane htmlPane = new JEditorPane(); String description = "<html><body>Hello<table border=1>" + "<tr><td><img alt='Bad' src='http://www.java2s.com/style/download.png'/></tr></td></table></body></html>"; htmlPane.setContentType("text/html"); htmlPane.setText(description);//from ww w. ja v a 2s .c o m JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JScrollPane(htmlPane)); frame.pack(); frame.setVisible(true); }