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:moviedatas.MovieDatas.java

public static void main(String[] args) {
    FilterController fpc = new FilterController();

    SortController spc = new SortController();

    //1. Create the frame.
    JFrame frame = new JFrame("Movies Open Datas by Harp-e");
    frame.setPreferredSize(new Dimension(1280, 800));

    //2. Optional: What happens when the frame closes?
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    MovieListView movieListView = new MovieListView();
    JPanel movieListPanel = movieListView.createViewPanel();
    TitledBorder moviesTitle;//from  w  w  w  .  j a  v  a 2 s.  co m
    moviesTitle = BorderFactory.createTitledBorder("Movies");
    movieListPanel.setBorder(moviesTitle);

    //3. Create components and put them in the frame.
    //----------------------------------------------------------------------
    // Sort & Filter panel (right)
    //----------------------------------------------------------------------
    SortPanelView sortFilterView = new SortPanelView();
    FilterPanelView filterPanelView = new FilterPanelView();

    JPanel sortPanel = sortFilterView.createSortPanel();
    JPanel filterPanel = filterPanelView.createFilterPanel();
    JPanel sortFilterPanel = new JPanel();

    sortFilterPanel.setLayout(new BoxLayout(sortFilterPanel, BoxLayout.PAGE_AXIS));

    sortFilterPanel.add(sortPanel);
    sortFilterPanel.add(filterPanel);

    frame.getContentPane().add(sortFilterPanel, BorderLayout.WEST);
    //----------------------------------------------------------------------
    // Movie Info Panel (left)
    //----------------------------------------------------------------------
    MovieInfoController movieInfoController = new MovieInfoController();
    JPanel movieInfoView = movieInfoController.initView();
    TitledBorder infoTitle;
    infoTitle = BorderFactory.createTitledBorder("Informations");
    movieInfoView.setBorder(infoTitle);
    //----------------------------------------------------------------------
    // Movie List Panel (middle)
    //----------------------------------------------------------------------   
    JPanel listPanel = new JPanel();
    listPanel.setLayout(new BorderLayout());
    listPanel.setPreferredSize(new Dimension(1280, 400));
    listPanel.add(sortFilterPanel, BorderLayout.WEST);
    listPanel.add(movieInfoView, BorderLayout.EAST);
    listPanel.add(movieListPanel, BorderLayout.CENTER);
    frame.getContentPane().add(listPanel, BorderLayout.NORTH);
    //----------------------------------------------------------------------
    // Charts Panel (bottom)
    //----------------------------------------------------------------------
    JPanel chartPanel = new JPanel();

    // Spider chart Panel
    //______________________________________________________________________
    // Create the panel
    JPanel spiderPanel = new JPanel();
    // Create the view
    SpiderChartView spiderChartView = new SpiderChartView();
    // Create a tilte
    TitledBorder spiderTitle;
    // Put a border around the title
    spiderTitle = BorderFactory.createTitledBorder("Spider chart");
    // Put the border on the panel
    spiderPanel.setBorder(spiderTitle);
    // Put the view on the panel
    spiderPanel.add(spiderChartView.initView());
    // Put the spider panel on the global panel
    chartPanel.add(spiderPanel);
    //______________________________________________________________________

    // Bar chart Panel
    //______________________________________________________________________
    JPanel barPanel = new JPanel();
    BarChartView barChartView = new BarChartView();
    TitledBorder barTitle;
    barTitle = BorderFactory.createTitledBorder("Bar chart");
    barPanel.setBorder(barTitle);
    barPanel.add(barChartView.initView());
    chartPanel.add(barPanel);
    //______________________________________________________________________

    // Global chart Panel
    //______________________________________________________________________
    JPanel globalChartPanel = new JPanel();
    GlobalChart globalChartView = new GlobalChart();
    TitledBorder globalTitle;
    globalTitle = BorderFactory.createTitledBorder("Global chart");
    globalChartPanel.setBorder(globalTitle);
    globalChartPanel.add(globalChartView.initView());
    chartPanel.add(globalChartPanel);
    //______________________________________________________________________

    frame.getContentPane().add(chartPanel, BorderLayout.CENTER);
    //----------------------------------------------------------------------

    //4. Size the frame.
    frame.pack();

    //5. Show it.
    frame.setVisible(true);
    //ArrayList<Movie> movies = new ArrayList<>();
    //FilterController.filter(10,SortController.byTitle(movies));

}

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 ww  w .j  a  v  a2  s  . 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 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  va2 s  . 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);
}

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  w ww .  ja  v  a 2  s  .  c  om
    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:Main.java

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

    JPanel mainPanel = new JPanel();
    JPanel buttonsPanel = new JPanel();
    frame.add(mainPanel);//  w w w.  ja va 2 s  .c  o  m
    frame.add(buttonsPanel, BorderLayout.SOUTH);

    String[] options = { "S", "G", "I", "T" };

    JComboBox comboBox = new JComboBox(options);
    comboBox.setRenderer(new MyComboBoxRenderer("COUNTRY"));
    comboBox.setSelectedIndex(-1);
    mainPanel.add(comboBox);

    JButton clearSelectionButton = new JButton("Clear selection");
    clearSelectionButton.addActionListener(e -> {
        comboBox.setSelectedIndex(-1);
    });
    buttonsPanel.add(clearSelectionButton);

    frame.pack();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:OverlaySample.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;
        }//from w ww  .  j a  v  a  2  s .c om
    };
    LayoutManager overlay = new OverlayLayout(panel);
    panel.setLayout(overlay);

    JButton button = new JButton("Small");
    button.setMaximumSize(new Dimension(25, 25));
    button.setBackground(Color.white);
    panel.add(button);

    button = new JButton("Medium");
    button.setMaximumSize(new Dimension(50, 50));
    button.setBackground(Color.gray);
    panel.add(button);

    button = new JButton("Large");
    button.setMaximumSize(new Dimension(100, 100));
    button.setBackground(Color.black);
    panel.add(button);

    frame.add(panel, BorderLayout.CENTER);

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

From source file:ColorAction.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setTitle("SeparateGUITest");
    frame.setSize(300, 200);//from  w ww  .ja  v a 2 s  .c  o m
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    JPanel panel = new JPanel();

    Action blueAction = new ColorAction("Blue", new ImageIcon("blue-ball.gif"), Color.blue, panel);
    Action yellowAction = new ColorAction("Yellow", new ImageIcon("yellow-ball.gif"), Color.yellow, panel);
    Action redAction = new ColorAction("Red", new ImageIcon("red-ball.gif"), Color.red, panel);

    panel.add(new JButton(yellowAction));
    panel.add(new JButton(blueAction));
    panel.add(new JButton(redAction));

    panel.registerKeyboardAction(yellowAction, KeyStroke.getKeyStroke(KeyEvent.VK_Y, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);
    panel.registerKeyboardAction(blueAction, KeyStroke.getKeyStroke(KeyEvent.VK_B, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);
    panel.registerKeyboardAction(redAction, KeyStroke.getKeyStroke(KeyEvent.VK_R, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

    Container contentPane = frame.getContentPane();
    contentPane.add(panel);

    JMenu m = new JMenu("Color");
    m.add(yellowAction);
    m.add(blueAction);
    m.add(redAction);
    JMenuBar mbar = new JMenuBar();
    mbar.add(m);
    frame.setJMenuBar(mbar);

    frame.show();
}

From source file:CustomTreeCellRenderer.java

public static void main(String[] args) {
    ImageIcon iconWhite = new ImageIcon("white.jpg");
    ImageIcon iconBlack = new ImageIcon("black.jpg");
    ;//w w w .  j  ava  2 s  .  co  m
    JFrame frame = new JFrame();
    frame.setContentPane(new JPanel(new BorderLayout()));

    JTree tree = new JTree();
    frame.getContentPane().add(tree);

    CustomTreeCellRenderer renderer = new CustomTreeCellRenderer();
    renderer.setRendererIcon(iconWhite);
    tree.setCellRenderer(renderer);

    JPanel panelButtons = new JPanel();

    JButton buttonWhite = new JButton("");
    buttonWhite.setIcon(iconWhite);
    JButton buttonBlack = new JButton("");
    buttonBlack.setIcon(iconBlack);

    buttonBlack.addActionListener(e -> {
        renderer.setRendererIcon(iconBlack);
        tree.repaint();
    });

    panelButtons.add(buttonBlack);
    panelButtons.add(buttonWhite);
    frame.getContentPane().add(panelButtons, BorderLayout.SOUTH);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500, 500);
    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 panel = new JPanel();
    final JButton button = new JButton("Select files...");
    button.addActionListener(e -> {/*from   ww w .  j  a  v  a  2s .  c  o  m*/
        final JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(chooser.getFileSystemView().getParentDirectory(new File("C:\\")));
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.showDialog(button, "Select file");
    });
    panel.add(button);
    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
}

From source file:EditorDropTarget2.java

public static void main(String[] args) {
    try {/*  ww  w .  ja  va  2s.  c o m*/
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    final JFrame f = new JFrame("JEditor Pane Drop Target Example 2");

    final JEditorPane pane = new JEditorPane();

    // Add a drop target to the JEditorPane
    EditorDropTarget2 target = new EditorDropTarget2(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());
        }
    });

    f.getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER);
    f.getContentPane().add(panel, BorderLayout.SOUTH);
    f.setSize(500, 400);
    f.setVisible(true);
}