List of usage examples for javax.swing JPanel JPanel
public JPanel()
JPanel
with a double buffer and a flow layout. From source file:Main.java
public static void main(String[] args) { JProgressBar progressBar = new JProgressBar(); progressBar.setOpaque(false);/*from ww w.j av a 2 s . c o m*/ progressBar.setUI(new GradientPalletProgressBarUI()); JPanel p = new JPanel(); p.add(progressBar); p.add(new JButton(new AbstractAction("Start") { @Override public void actionPerformed(ActionEvent e) { SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override public Void doInBackground() { int current = 0, lengthOfTask = 100; while (current <= lengthOfTask && !isCancelled()) { try { Thread.sleep(50); } catch (Exception ie) { return null; } setProgress(100 * current / lengthOfTask); current++; } return null; } }; worker.addPropertyChangeListener(new ProgressListener(progressBar)); worker.execute(); } })); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.getContentPane().add(p); frame.setSize(320, 240); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { String mapUrlPath = "http://www.java2s.com/style/download.png"; URL mapUrl = new URL(mapUrlPath); BufferedImage mapImage = ImageIO.read(mapUrl); Image newMapImage = Toolkit.getDefaultToolkit() .createImage(new FilteredImageSource(mapImage.getSource(), new XorFilter())); ImageIcon mapIcon = new ImageIcon(mapImage); ImageIcon newMapIcon = new ImageIcon(newMapImage); JPanel imagePanel = new JPanel(); imagePanel.add(new JLabel(mapIcon)); imagePanel.add(new JLabel(newMapIcon)); JOptionPane.showMessageDialog(null, imagePanel); }
From source file:CutPasteSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Cut/Paste Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField(); frame.add(textField, BorderLayout.NORTH); Action actions[] = textField.getActions(); Action cutAction = findAction(actions, DefaultEditorKit.cutAction); Action copyAction = findAction(actions, DefaultEditorKit.copyAction); Action pasteAction = findAction(actions, DefaultEditorKit.pasteAction); JPanel panel = new JPanel(); frame.add(panel, BorderLayout.SOUTH); JButton cutButton = new JButton(cutAction); cutButton.setText("Cut"); panel.add(cutButton);/*from w w w .j a v a 2 s. c o m*/ JButton copyButton = new JButton(copyAction); copyButton.setText("Copy"); panel.add(copyButton); JButton pasteButton = new JButton(pasteAction); pasteButton.setText("Paste"); panel.add(pasteButton); frame.setSize(250, 250); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { String mapUrlPath = "http://www.java2s.com/style/download.png"; URL mapUrl = new URL(mapUrlPath); BufferedImage mapImage = ImageIO.read(mapUrl); Image newMapImage = Toolkit.getDefaultToolkit() .createImage(new FilteredImageSource(mapImage.getSource(), new GrayFilter())); ImageIcon mapIcon = new ImageIcon(mapImage); ImageIcon newMapIcon = new ImageIcon(newMapImage); JPanel imagePanel = new JPanel(); imagePanel.add(new JLabel(mapIcon)); imagePanel.add(new JLabel(newMapIcon)); JOptionPane.showMessageDialog(null, imagePanel); }
From source file:Main.java
public static void main(String[] args) throws Exception { String mapUrlPath = "http://www.java2s.com/style/download.png"; URL mapUrl = new URL(mapUrlPath); BufferedImage mapImage = ImageIO.read(mapUrl); Image newMapImage = Toolkit.getDefaultToolkit() .createImage(new FilteredImageSource(mapImage.getSource(), new RedBlueSwapFilter())); ImageIcon mapIcon = new ImageIcon(mapImage); ImageIcon newMapIcon = new ImageIcon(newMapImage); JPanel imagePanel = new JPanel(); imagePanel.add(new JLabel(mapIcon)); imagePanel.add(new JLabel(newMapIcon)); JOptionPane.showMessageDialog(null, imagePanel); }
From source file:MaxLengthDocument.java
public static void main(String[] a) { Document doc = new MaxLengthDocument(5); // set maximum length to 5 JTextField field = new JTextField(doc, "", 8); JPanel flowPanel = new JPanel(); flowPanel.add(field);/* ww w . ja va 2 s .c o m*/ JFrame frame = new JFrame("MaxLengthDocument demo"); frame.setContentPane(flowPanel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(160, 80); frame.setVisible(true); }
From source file:DefaultSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Default Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField(); frame.add(textField, BorderLayout.NORTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println(actionEvent.getActionCommand() + " selected"); }//ww w .j a va 2 s . c o m }; JPanel panel = new JPanel(); JButton defaultButton = new JButton("Default Button"); defaultButton.addActionListener(actionListener); panel.add(defaultButton); JButton otherButton = new JButton("Other Button"); otherButton.addActionListener(actionListener); panel.add(otherButton); frame.add(panel, BorderLayout.SOUTH); Keymap keymap = textField.getKeymap(); KeyStroke keystroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false); keymap.removeKeyStrokeBinding(keystroke); frame.getRootPane().setDefaultButton(defaultButton); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JScrollPane sPane = new JScrollPane(); sPane.setPreferredSize(new Dimension(200, 150)); JButton button = new JButton(new AbstractAction("Create Table") { public void actionPerformed(ActionEvent arg0) { DefaultTableModel model = new DefaultTableModel(new Integer[][] { { 1, 2 }, { 3, 4 } }, new String[] { "A", "B" }); JTable table = new JTable(model); sPane.getViewport().add(table); }// w w w.ja v a2s. c o m }); JPanel panel = new JPanel(); panel.add(sPane); panel.add(button); JOptionPane.showMessageDialog(null, panel); }
From source file:Main.java
public static void main(String args[]) { SpinnerNumberModel model = new SpinnerNumberModel(0.0, -1000.0, 1000.0, 0.1); JSpinner s = new JSpinner(model); JSpinner.NumberEditor editor = new JSpinner.NumberEditor(s); s.setEditor(editor);/*from w w w . ja v a2 s . c o m*/ JTextField stepText = new JTextField(10); JButton bStepSet = new JButton("Set Step"); bStepSet.addActionListener(e -> { Double val = Double.parseDouble(stepText.getText().trim()); model.setStepSize(val); }); JFrame f = new JFrame(); Container c = f.getContentPane(); c.add(s); JPanel southPanel = new JPanel(); southPanel.add(stepText); southPanel.add(bStepSet); c.add(southPanel, BorderLayout.SOUTH); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { String mapUrlPath = "http://www.java2s.com/style/download.png"; URL mapUrl = new URL(mapUrlPath); BufferedImage mapImage = ImageIO.read(mapUrl); Image newMapImage = Toolkit.getDefaultToolkit() .createImage(new FilteredImageSource(mapImage.getSource(), new GrayToColorFilter(Color.red))); ImageIcon mapIcon = new ImageIcon(mapImage); ImageIcon newMapIcon = new ImageIcon(newMapImage); JPanel imagePanel = new JPanel(); imagePanel.add(new JLabel(mapIcon)); imagePanel.add(new JLabel(newMapIcon)); JOptionPane.showMessageDialog(null, imagePanel); }