Example usage for javax.swing JPanel add

List of usage examples for javax.swing JPanel add

Introduction

In this page you can find the example usage for javax.swing JPanel add.

Prototype

public Component add(Component comp) 

Source Link

Document

Appends the specified component to the end of this container.

Usage

From source file:Main.java

public static void main(String[] args) {

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    JPanel panel = new JPanel();
    Container c = frame.getContentPane();
    panel.setSize(100, 100);/*from www  .j a  v a 2s. c  o m*/
    panel.setLayout(new GridLayout(1000, 1));
    for (int i = 0; i < 1000; i++)
        panel.add(new JLabel("JLabel " + i));

    JScrollPane jsp = new JScrollPane(panel);
    c.add(jsp);
    frame.setSize(100, 100);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JTextField textField = new JTextField();

    JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL);

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    BoundedRangeModel brm = textField.getHorizontalVisibility();
    scrollBar.setModel(brm);//from   w w  w  .j  a  v  a  2  s . c o m
    panel.add(textField);
    panel.add(scrollBar);

    frame.add(panel, BorderLayout.NORTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel contentPane = new JPanel();
    JTextField tField = new JTextField(10);
    ((AbstractDocument) tField.getDocument()).setDocumentFilter(new MyDocumentFilter());
    contentPane.add(tField);

    frame.setContentPane(contentPane);/*from  w  ww  .j  av  a2 s  .  c  o  m*/
    frame.pack();
    frame.setVisible(true);
}

From source file:com.joey.software.dsp.HilbertTransform.java

public static void main(String input[]) {
    int length = 5000;

    float[] reInput = FFTSpeedTest.getSinData(length, 1000);
    float[] imInput = FFTSpeedTest.getStaticData(length, 0f);

    float[] reOutput = new float[length];
    float[] imOutput = new float[length];

    FastFourierTransform3 fft = new FastFourierTransform3(length);
    fft.fft(reInput, imInput, reOutput, imOutput);

    HilbertTransform ht = new HilbertTransform();
    getHilbert(reInput, imInput, reOutput, imOutput);

    JFreeChart inputPlot = PlotingToolkit.getPlot(new float[][] { reInput, imInput },
            new String[] { "Real", "Imaginary" }, "Input Data", "X Data", "Y Data");

    JFreeChart outputPlot = PlotingToolkit.getPlot(new float[][] { reOutput, imOutput },
            new String[] { "Real", "Imaginary" }, "Output Data", "X Data", "Y Data");

    ChartPanel p1 = new ChartPanel(inputPlot);
    ChartPanel p2 = new ChartPanel(outputPlot);

    JPanel p = new JPanel(new GridLayout(1, 2));
    p.add(p1);
    p.add(p2);/*from   w  w  w  .  j  a  v  a  2  s  . co m*/

    FrameFactroy.getFrame(p);
}

From source file:FocusCycleSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Focus Cycle Sample");

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(3, 3));
    for (int i = 0; i < 8; i++) {
        JButton button = new JButton("" + i);
        contentPane.add(button);//from w  ww .  j  a va2  s .c  o  m
    }

    JPanel panel = new FocusCycleConstrainedJPanel();
    panel.setLayout(new GridLayout(1, 3));
    for (int i = 0; i < 3; i++) {
        JButton button = new JButton("" + (i + 3));
        panel.add(button);
    }
    contentPane.add(panel);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JPanel JMainPanel = new JPanel(new BorderLayout());
    JPanel jp = new JPanel();
    JComboBox combo = new JComboBox(new String[] { "Item1", "Item2", "Item3" });
    JPanel jImage = new JPanel();
    JFrame jf = new JFrame();

    jp.add(combo);
    JMainPanel.add(jp, BorderLayout.WEST);
    JMainPanel.add(jImage, BorderLayout.CENTER);
    jp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.ALT_DOWN_MASK), "screenshot");
    jp.getActionMap().put("screenshot", new AbstractAction() {
        @Override//from w w w. j av a 2 s .c o m
        public void actionPerformed(ActionEvent arg0) {
            final BufferedImage bf = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB);
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    jf.getRootPane().paint(bf.getGraphics());
                    jImage.getGraphics().drawImage(bf, 0, 0, jImage);
                }
            });
        }
    });
    jf.getContentPane().add(JMainPanel);
    jf.setSize(500, 500);
    jf.setVisible(true);
}

From source file:TextSlider.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Text Slider");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JTextField textField = new JTextField();

    JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL);

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    BoundedRangeModel brm = textField.getHorizontalVisibility();
    scrollBar.setModel(brm);//from   ww w  .  ja  v  a2s  .com
    panel.add(textField);
    panel.add(scrollBar);

    final TextSlider ts = new TextSlider();
    textField.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Text: " + textField.getText());
        }
    });
    frame.add(panel, BorderLayout.NORTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:SaveImage.java

public static void main(String s[]) {
    JFrame f = new JFrame("Save Image Sample");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*w  w  w.jav  a  2s  .  c o  m*/
        }
    });
    SaveImage si = new SaveImage();
    f.add("Center", si);
    JComboBox choices = new JComboBox(si.getDescriptions());
    choices.setActionCommand("SetFilter");
    choices.addActionListener(si);
    JComboBox formats = new JComboBox(si.getFormats());
    formats.setActionCommand("Formats");
    formats.addActionListener(si);
    JPanel panel = new JPanel();
    panel.add(choices);
    panel.add(new JLabel("Save As"));
    panel.add(formats);
    f.add("South", panel);
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {

    final JTextField textField = new JTextField();

    JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL);

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    BoundedRangeModel brm = textField.getHorizontalVisibility();
    scrollBar.setModel(brm);/*  w  w w .j  a v a 2s  .c o m*/
    panel.add(textField);
    panel.add(scrollBar);

    textField.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Text: " + textField.getText());
        }
    });

    JFrame frame = new JFrame("Text Slider");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.add(panel, BorderLayout.NORTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:CutPasteSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Cut/Paste Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = frame.getContentPane();

    JTextField textField = new JTextField();
    JTextArea textArea = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(textArea);

    content.add(textField, BorderLayout.NORTH);
    content.add(scrollPane, BorderLayout.CENTER);

    Action actions[] = textField.getActions();

    Action cutAction = TextUtilities.findAction(actions, DefaultEditorKit.cutAction);
    Action copyAction = TextUtilities.findAction(actions, DefaultEditorKit.copyAction);
    Action pasteAction = TextUtilities.findAction(actions, DefaultEditorKit.pasteAction);

    JPanel panel = new JPanel();
    content.add(panel, BorderLayout.SOUTH);

    JButton cutButton = new JButton(cutAction);
    cutButton.setText("Cut");
    panel.add(cutButton);

    JButton copyButton = new JButton(copyAction);
    copyButton.setText("Copy");
    panel.add(copyButton);/*from   w  w  w .j a v  a 2s.co m*/

    JButton pasteButton = new JButton(pasteAction);
    pasteButton.setText("Paste");
    panel.add(pasteButton);

    frame.setSize(250, 250);
    frame.setVisible(true);
}