List of usage examples for javax.swing JPanel add
public Component add(Component comp)
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;/*from w w w .j av a2 s.com*/ JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format number = NumberFormat.getNumberInstance(Locale.FRENCH); label = new JLabel("French Number:"); input = new JFormattedTextField(number); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;// w ww .ja v a 2 s .c o m JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format currency = NumberFormat.getCurrencyInstance(Locale.UK); label = new JLabel("UK Currency:"); input = new JFormattedTextField(currency); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:NumberFormatgetNumberInstanceLocaleFRENCH.java
public static void main(String args[]) { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;//from w ww . j a v a2 s. c o m JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format number = NumberFormat.getNumberInstance(Locale.FRENCH); label = new JLabel("French Number:"); input = new JFormattedTextField(number); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.add(new JTextField()); frame.pack(); frame.setVisible(true); }
From source file:NumberInputSampleLocaleUK.java
public static void main(String args[]) { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;/*from w w w. j ava 2 s. co m*/ JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format currency = NumberFormat.getCurrencyInstance(Locale.UK); label = new JLabel("UK Currency:"); input = new JFormattedTextField(currency); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.add(new JTextField()); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;//from w ww .ja va2 s .c om JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format integer = NumberFormat.getIntegerInstance(Locale.ITALIAN); label = new JLabel("Italian integer:"); input = new JFormattedTextField(integer); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws UnsupportedEncodingException { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); JPanel buttons = new JPanel(); JScrollPane pane = new JScrollPane(buttons); pane.getViewport().addChangeListener(e -> { System.out.println("Change in " + e.getSource()); System.out.println("Vertical visible? " + pane.getVerticalScrollBar().isVisible()); System.out.println("Horizontal visible? " + pane.getHorizontalScrollBar().isVisible()); });//from ww w . j a va 2s . co m panel.add(pane); frame.setContentPane(panel); frame.setSize(300, 200); frame.setVisible(true); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { for (int i = 0; i < 10; i++) { Thread.sleep(800); buttons.add(new JButton("Hello " + i)); buttons.revalidate(); } return null; } }; worker.execute(); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Overlay Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel() { public boolean isOptimizedDrawingEnabled() { return false; }// w w w . j a va2s .c o m }; LayoutManager overlay = new OverlayLayout(panel); panel.setLayout(overlay); JButton button = new JButton("Small"); button.setMaximumSize(new Dimension(25, 25)); button.setBackground(Color.white); button.setAlignmentX(0.0f); button.setAlignmentY(0.0f); panel.add(button); button = new JButton("Medium"); button.setMaximumSize(new Dimension(50, 50)); button.setBackground(Color.gray); button.setAlignmentX(0.0f); button.setAlignmentY(0.0f); panel.add(button); button = new JButton("Large"); button.setMaximumSize(new Dimension(100, 100)); button.setBackground(Color.black); button.setAlignmentX(0.0f); button.setAlignmentY(0.0f); panel.add(button); frame.add(panel, BorderLayout.CENTER); frame.setSize(400, 300); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(); panel.setLayout(new OverlayLayout(panel)); JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.add("1", new JTextField("one")); tabbedPane.add("2", new JTextField("two")); tabbedPane.setAlignmentX(1.0f);// ww w . ja v a2s . c o m tabbedPane.setAlignmentY(0.0f); JCheckBox checkBox = new JCheckBox("Add tab"); checkBox.setOpaque(false); checkBox.setAlignmentX(1.0f); checkBox.setAlignmentY(0.0f); panel.add(checkBox); panel.add(tabbedPane); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.setSize(400, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(); panel.setLayout(new OverlayLayout(panel)); JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.add("1", new JTextField("one")); tabbedPane.add("2", new JTextField("two")); tabbedPane.setAlignmentX(1.0f);/*w w w.j a v a 2 s.c o m*/ tabbedPane.setAlignmentY(0.0f); JCheckBox checkBox = new JCheckBox("Check Me"); checkBox.setOpaque(false); checkBox.setAlignmentX(1.0f); checkBox.setAlignmentY(0.0f); panel.add(checkBox); panel.add(tabbedPane); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.setLocationByPlatform(true); frame.setSize(400, 100); frame.setVisible(true); }
From source file:EditorDropTarget3.java
public static void main(String[] args) { try {/*from w w w. j av a 2 s. c om*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } final JFrame f = new JFrame("JEditor Pane Drop Target Example 3"); final JEditorPane pane = new JEditorPane(); // Add a drop target to the JEditorPane EditorDropTarget3 target = new EditorDropTarget3(pane); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); JPanel panel = new JPanel(); final JCheckBox editable = new JCheckBox("Editable"); editable.setSelected(true); panel.add(editable); editable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEditable(editable.isSelected()); } }); final JCheckBox enabled = new JCheckBox("Enabled"); enabled.setSelected(true); panel.add(enabled); enabled.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEnabled(enabled.isSelected()); } }); f.getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER); f.getContentPane().add(panel, BorderLayout.SOUTH); f.setSize(500, 400); f.setVisible(true); }