List of usage examples for java.awt FlowLayout FlowLayout
public FlowLayout(int align)
From source file:Main.java
private JPanel makeHorizontalPanel(String... labelValues) { JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); for (String s : labelValues) { JLabel label = new JLabel(s); panel.add(label);/*from w w w . j a v a 2 s . c o m*/ } return panel; }
From source file:TextForm.java
public TextForm(String[] labels, char[] mnemonics, int[] widths, String[] tips) { super(new BorderLayout()); JPanel labelPanel = new JPanel(new GridLayout(labels.length, 1)); JPanel fieldPanel = new JPanel(new GridLayout(labels.length, 1)); add(labelPanel, BorderLayout.WEST); add(fieldPanel, BorderLayout.CENTER); fields = new JTextField[labels.length]; for (int i = 0; i < labels.length; i += 1) { fields[i] = new JTextField(); if (i < tips.length) fields[i].setToolTipText(tips[i]); if (i < widths.length) fields[i].setColumns(widths[i]); JLabel lab = new JLabel(labels[i], JLabel.RIGHT); lab.setLabelFor(fields[i]);//w ww . ja va 2s . co m if (i < mnemonics.length) lab.setDisplayedMnemonic(mnemonics[i]); labelPanel.add(lab); JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT)); p.add(fields[i]); fieldPanel.add(p); } }
From source file:SwingSuspendResume.java
public SwingSuspendResume() { symbolTF = new JTextField(); symbolTF.setEditable(false);//from ww w. j av a2s . com symbolTF.setFont(new Font("Monospaced", Font.BOLD, 26)); symbolTF.setHorizontalAlignment(JTextField.CENTER); final JButton suspendB = new JButton("Suspend"); final JButton resumeB = new JButton("Resume"); suspendB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { suspendNow(); } }); resumeB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { resumeNow(); } }); JPanel innerStackP = new JPanel(); innerStackP.setLayout(new GridLayout(0, 1, 3, 3)); innerStackP.add(symbolTF); innerStackP.add(suspendB); innerStackP.add(resumeB); this.setLayout(new FlowLayout(FlowLayout.CENTER)); this.add(innerStackP); }
From source file:com.game.ui.views.UserDialog.java
public UserDialog(String message, JFrame frame) { setLayout(new BorderLayout(5, 5)); setModalityType(ModalityType.APPLICATION_MODAL); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setResizable(false);/*from w w w .j ava 2 s .co m*/ ImageIcon icon = null; try { icon = GameUtils.shrinkImage("warning.gif", 30, 30); } catch (IOException e) { System.out.println("Dialog : showDialogForMap(): Exception occured :" + e); e.printStackTrace(); } JPanel panel = new JPanel(); JLabel label = new JLabel(icon); panel.setLayout(new FlowLayout(FlowLayout.LEFT)); label.setText(message); label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); label.setHorizontalAlignment(0); panel.add(label); add(panel, BorderLayout.NORTH); JPanel contentPanel = new JPanel(); contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS)); txt = new JTextField(); txt.setPreferredSize(new Dimension(150, 30)); txt.setAlignmentX(.5f); txt.setMaximumSize(new Dimension(150, 30)); contentPanel.add(txt); contentPanel.add(Box.createVerticalStrut(10)); JButton btn = new JButton("Submit."); btn.setAlignmentX(.5f); btn.setPreferredSize(new Dimension(50, 25)); btn.addActionListener(this); validationMess = new JLabel("All fields are mandatory"); validationMess.setVisible(false); validationMess.setForeground(Color.red); validationMess.setAlignmentX(.5f); contentPanel.add(btn); contentPanel.add(Box.createVerticalStrut(10)); contentPanel.add(validationMess); contentPanel.add(Box.createVerticalGlue()); add(contentPanel, BorderLayout.CENTER); pack(); setSize(new Dimension(300, 200)); setLocationRelativeTo(frame); setVisible(true); }
From source file:Main.java
public Main() throws HeadlessException { setSize(200, 200);/* www.j av a 2 s . co m*/ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button1 = new JButton("Message dialog"); button1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog((Component) e.getSource(), "Thank you!"); } }); JButton button2 = new JButton("Input dialog"); button2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String text = JOptionPane.showInputDialog((Component) e.getSource(), "What is your name?"); if (text != null && !text.equals("")) { JOptionPane.showMessageDialog((Component) e.getSource(), "Hello " + text); } } }); JButton button3 = new JButton("Yes no dialog"); button3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int result = JOptionPane.showConfirmDialog((Component) e.getSource(), "Close this application?"); if (result == JOptionPane.YES_OPTION) { System.exit(0); } else if (result == JOptionPane.NO_OPTION) { System.out.println("Do nothing"); } } }); setLayout(new FlowLayout(FlowLayout.CENTER)); getContentPane().add(button1); getContentPane().add(button2); getContentPane().add(button3); }
From source file:Main.java
public ConfirmDialog(Frame parent) { super(parent, true); JPanel gui = new JPanel(new BorderLayout(3, 3)); gui.setBorder(new EmptyBorder(5, 5, 5, 5)); content = new JPanel(new BorderLayout()); gui.add(content, BorderLayout.CENTER); JPanel buttons = new JPanel(new FlowLayout(4)); gui.add(buttons, BorderLayout.SOUTH); JButton ok = new JButton("OK"); buttons.add(ok);/*from ww w . ja v a2s .c om*/ ok.addActionListener(e -> { result = OK_OPTION; setVisible(false); }); JButton cancel = new JButton("Cancel"); buttons.add(cancel); cancel.addActionListener(e -> { result = CANCEL_OPTION; setVisible(false); }); setContentPane(gui); }
From source file:userinterface.graph.GraphOptions.java
/** Creates a new instance of MultiGraphOptions */ public GraphOptions(GUIPlugin plugin, JPanel theModel, JFrame gui, String title) { super(gui, title); gop = new GraphOptionsPanel(plugin, gui, theModel); gop.setPreferredSize(new Dimension(400, 650)); this.getContentPane().add(gop); JPanel p = new JPanel(new FlowLayout(FlowLayout.RIGHT)); this.getContentPane().add(p, BorderLayout.SOUTH); this.getContentPane().setSize(400, 650); JButton jb = new JButton("Close"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { gop.stopEditors();/*from w w w. j a v a 2 s.co m*/ setVisible(false); } }); jb.addFocusListener(new FocusListener() { /** * Invoked when a component gains the keyboard focus. */ public void focusGained(FocusEvent e) { } /** * Invoked when a component loses the keyboard focus. */ public void focusLost(FocusEvent e) { //gop.stopEditors(); } }); p.add(jb); pack(); setLocationRelativeTo(getParent()); // centre //show(); setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE); }
From source file:freemrs.ChartPanelDraw.java
public ChartPanelDraw(java.util.List<Vitals> result, String type) { this.type = type; this.result = result; dataset = createTimeDataset();/*from w ww . j av a2 s. c om*/ chartPanel = createChart(dataset, type); JFrame f = new JFrame("Vital Plot"); //Jframe to draw the graph f.setTitle("Vital Plot"); f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); f.setLayout(new BorderLayout(0, 5)); f.add(chartPanel, BorderLayout.CENTER); f.setIconImage(new ImageIcon(getClass().getResource("/images/icon_transparent.png")).getImage()); chartPanel.setHorizontalAxisTrace(true); //set properties of the graph chartPanel.setVerticalAxisTrace(true); chartPanel.setMouseWheelEnabled(true); JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(createTrace()); //Add components to panel panel.add(createDate()); panel.add(createZoom()); f.add(panel, BorderLayout.SOUTH); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:EHRAppointment.ChartPanelDraw.java
/** * * @param result/*from w w w . j a v a 2 s . c om*/ * @param type */ public ChartPanelDraw(java.util.List<Vitals> result, String type) { this.type = type; this.result = result; dataset = createTimeDataset(); chartPanel = createChart(dataset, type); JFrame f = new JFrame("Vital Plot"); //Jframe to draw the graph f.setTitle("Vital Plot"); f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); f.setLayout(new BorderLayout(0, 5)); f.add(chartPanel, BorderLayout.CENTER); f.setIconImage(new ImageIcon(getClass().getResource("/images/icon_transparent.png")).getImage()); chartPanel.setHorizontalAxisTrace(true); //set properties of the graph chartPanel.setVerticalAxisTrace(true); chartPanel.setMouseWheelEnabled(true); JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(createTrace()); //Add components to panel panel.add(createDate()); panel.add(createZoom()); f.add(panel, BorderLayout.SOUTH); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:SliderTest.java
public SliderTestFrame() { setTitle("SliderTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); sliderPanel = new JPanel(); sliderPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); // common listener for all sliders listener = new ChangeListener() { public void stateChanged(ChangeEvent event) { // update text field when the slider value changes JSlider source = (JSlider) event.getSource(); textField.setText("" + source.getValue()); }//from w w w. j a v a2 s. c o m }; // add a plain slider JSlider slider = new JSlider(); addSlider(slider, "Plain"); // add a slider with major and minor ticks slider = new JSlider(); slider.setPaintTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); addSlider(slider, "Ticks"); // add a slider that snaps to ticks slider = new JSlider(); slider.setPaintTicks(true); slider.setSnapToTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); addSlider(slider, "Snap to ticks"); // add a slider with no track slider = new JSlider(); slider.setPaintTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); slider.setPaintTrack(false); addSlider(slider, "No track"); // add an inverted slider slider = new JSlider(); slider.setPaintTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); slider.setInverted(true); addSlider(slider, "Inverted"); // add a slider with numeric labels slider = new JSlider(); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); addSlider(slider, "Labels"); // add a slider with alphabetic labels slider = new JSlider(); slider.setPaintLabels(true); slider.setPaintTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); Dictionary<Integer, Component> labelTable = new Hashtable<Integer, Component>(); labelTable.put(0, new JLabel("A")); labelTable.put(20, new JLabel("B")); labelTable.put(40, new JLabel("C")); labelTable.put(60, new JLabel("D")); labelTable.put(80, new JLabel("E")); labelTable.put(100, new JLabel("F")); slider.setLabelTable(labelTable); addSlider(slider, "Custom labels"); // add a slider with icon labels slider = new JSlider(); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.setSnapToTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(20); labelTable = new Hashtable<Integer, Component>(); // add card images labelTable.put(0, new JLabel(new ImageIcon("nine.gif"))); labelTable.put(20, new JLabel(new ImageIcon("ten.gif"))); labelTable.put(40, new JLabel(new ImageIcon("jack.gif"))); labelTable.put(60, new JLabel(new ImageIcon("queen.gif"))); labelTable.put(80, new JLabel(new ImageIcon("king.gif"))); labelTable.put(100, new JLabel(new ImageIcon("ace.gif"))); slider.setLabelTable(labelTable); addSlider(slider, "Icon labels"); // add the text field that displays the slider value textField = new JTextField(); add(sliderPanel, BorderLayout.CENTER); add(textField, BorderLayout.SOUTH); }