List of usage examples for javax.swing JPanel JPanel
public JPanel(boolean isDoubleBuffered)
JPanel
with FlowLayout
and the specified buffering strategy. From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JTextPane codearea = new JTextPane(); JScrollPane scroll;/*from ww w .ja v a 2s . co m*/ scroll = new JScrollPane(codearea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setPreferredSize(new Dimension(300, 300)); JPanel panel = new JPanel(new BorderLayout()); panel.add(scroll, BorderLayout.CENTER); JButton comp = new JButton("Print text"); comp.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println(codearea.getText()); } }); panel.add(comp, BorderLayout.SOUTH); frame.getContentPane().add(panel); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[][] data = { { "Data", "Data" } }; String[] col = { "Col", "Col" }; final DefaultTableModel model = new DefaultTableModel(data, col); JTable table = new JTable(model); JButton addRow = new JButton("Add Empty Row"); addRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { model.addRow(new Object[] {}); }/*from ww w . j a v a2 s .c o m*/ }); JPanel panel = new JPanel(new BorderLayout()); panel.add(new JScrollPane(table)); panel.add(addRow, BorderLayout.SOUTH); JOptionPane.showMessageDialog(null, panel); }
From source file:SpinnerDateStartEndSample.java
public static void main(String args[]) { JFrame frame = new JFrame("JSpinner Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Calendar cal = Calendar.getInstance(); Date now = cal.getTime();// w w w . j a va2s .c o m cal.add(Calendar.YEAR, -50); Date startDate = cal.getTime(); cal.add(Calendar.YEAR, 100); Date endDate = cal.getTime(); SpinnerModel model = new SpinnerDateModel(now, startDate, endDate, Calendar.YEAR); JSpinner spinner1 = new JSpinner(model); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(spinner1, BorderLayout.CENTER); frame.add(panel1, BorderLayout.SOUTH); frame.setSize(200, 90); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextPane text = new JTextPane() { @Override/*from ww w . j av a2 s . c om*/ public String getToolTipText() { return ((JComponent) getParent()).getToolTipText(); } @Override public String getToolTipText(MouseEvent event) { return ((JComponent) getParent()).getToolTipText(event); } }; text.setText("Lorem ipsum dolor sit"); ToolTipManager.sharedInstance().registerComponent(text); JFrame frame = new JFrame("Testing"); JPanel panel = new JPanel(new BorderLayout()); panel.setToolTipText("tooltip from parent"); frame.setContentPane(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(text); frame.pack(); frame.setVisible(true); }
From source file:CaretSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Caret Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); content.add(scrollPane, BorderLayout.CENTER); final JTextField dot = new JTextField(); dot.setEditable(false);//w ww. j av a 2 s. co m JPanel dotPanel = new JPanel(new BorderLayout()); dotPanel.add(new JLabel("Dot: "), BorderLayout.WEST); dotPanel.add(dot, BorderLayout.CENTER); content.add(dotPanel, BorderLayout.NORTH); final JTextField mark = new JTextField(); mark.setEditable(false); JPanel markPanel = new JPanel(new BorderLayout()); markPanel.add(new JLabel("Mark: "), BorderLayout.WEST); markPanel.add(mark, BorderLayout.CENTER); content.add(markPanel, BorderLayout.SOUTH); CaretListener listener = new CaretListener() { public void caretUpdate(CaretEvent caretEvent) { dot.setText("" + caretEvent.getDot()); mark.setText("" + caretEvent.getMark()); } }; textArea.addCaretListener(listener); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setSize(300, 500);/*from w w w. jav a2s .c o m*/ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel pan = new JPanel(new GridLayout(1, 1)); XmlJTree myTree = new XmlJTree(null); f.add(new JScrollPane(myTree)); JButton button = new JButton("Choose file"); button.addActionListener(e -> { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("XML file", "xml"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { myTree.setPath(chooser.getSelectedFile().getAbsolutePath()); } }); pan.add(button); f.add(pan, BorderLayout.SOUTH); f.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Mask Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label;//from www. ja v a2 s. c o m JFormattedTextField input; JPanel panel; MaskFormatter formatter; try { label = new JLabel("US Phone"); formatter = new MaskFormatter("'(###')' ###'-####"); formatter.setPlaceholderCharacter('*'); input = new JFormattedTextField(formatter); input.setColumns(20); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); } catch (ParseException e) { System.err.println("Unable to add Phone"); } 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 w w . j a va2s . c o m*/ JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); label = new JLabel("Raw Number:"); input = new JFormattedTextField(2424.50); 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) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame(); frame.setResizable(false);/*from w ww . ja v a2 s. c o m*/ removeButtons(frame); JPanel panel = new JPanel(new GridBagLayout()); JButton button = new JButton("Exit"); panel.add(button, new GridBagConstraints()); frame.getContentPane().add(panel); frame.setSize(400, 300); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); button.addActionListener(e -> System.exit(0)); }
From source file:Main.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 www .j av a 2s .c om*/ JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); label = new JLabel("Raw Number:"); input = new JFormattedTextField(2424.50); 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); }