Example usage for javax.swing JPanel setLayout

List of usage examples for javax.swing JPanel setLayout

Introduction

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

Prototype

public void setLayout(LayoutManager mgr) 

Source Link

Document

Sets the layout manager for this container.

Usage

From source file:ComboBoxDemo2.java

public ComboBoxDemo2() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    String[] patternExamples = { "dd MMMMM yyyy", "dd.MM.yy", "MM/dd/yy", "yyyy.MM.dd G 'at' hh:mm:ss z",
            "EEE, MMM d, ''yy", "h:mm a", "H:mm:ss:SSS", "K:mm a,z", "yyyy.MMMMM.dd GGG hh:mm aaa" };

    currentPattern = patternExamples[0];

    // Set up the UI for selecting a pattern.
    JLabel patternLabel1 = new JLabel("Enter the pattern string or");
    JLabel patternLabel2 = new JLabel("select one from the list:");

    JComboBox patternList = new JComboBox(patternExamples);
    patternList.setEditable(true);//from w ww  . ja  v  a 2 s  .com
    patternList.addActionListener(this);

    // Create the UI for displaying result.
    JLabel resultLabel = new JLabel("Current Date/Time", JLabel.LEADING); // ==
                                                                          // LEFT
    result = new JLabel(" ");
    result.setForeground(Color.black);
    result.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    // Lay out everything.
    JPanel patternPanel = new JPanel();
    patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.PAGE_AXIS));
    patternPanel.add(patternLabel1);
    patternPanel.add(patternLabel2);
    patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
    patternPanel.add(patternList);

    JPanel resultPanel = new JPanel(new GridLayout(0, 1));
    resultPanel.add(resultLabel);
    resultPanel.add(result);

    patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

    add(patternPanel);
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(resultPanel);

    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    reformat();
}

From source file:SliderControlPaintLine.java

public SliderControlPaintLine() {
    JPanel controlPanel = new JPanel();
    controlPanel.setLayout(new GridLayout(3, 3));
    getContentPane().add(controlPanel, BorderLayout.NORTH);

    JLabel label1 = new JLabel("Translate(dx,dy): ");
    JLabel label2 = new JLabel("Rotate(Theta,ox,oy): ");
    JLabel label3 = new JLabel("Scale(sx,sy)x10E-2:");

    controlPanel.add(label1);/* w  w  w .  j  a  v  a 2 s.  c om*/

    slider1 = createSlider(controlPanel, JSlider.HORIZONTAL, 0, 300, 150, 100, 50);
    slider2 = createSlider(controlPanel, JSlider.HORIZONTAL, 0, 300, 150, 100, 50);

    controlPanel.add(label2);

    slider3 = createSlider(controlPanel, JSlider.HORIZONTAL, 0, 360, 0, 90, 45);

    JPanel subPanel = new JPanel();
    subPanel.setLayout(new GridLayout(1, 2));

    slider4 = createSlider(subPanel, JSlider.HORIZONTAL, 0, 300, 150, 150, 50);
    slider5 = createSlider(subPanel, JSlider.HORIZONTAL, 0, 300, 150, 150, 50);
    controlPanel.add(subPanel);

    controlPanel.add(label3);

    slider6 = createSlider(controlPanel, JSlider.HORIZONTAL, 0, 200, 100, 100, 10);
    slider7 = createSlider(controlPanel, JSlider.HORIZONTAL, 0, 200, 100, 100, 10);

    JPanel widthPanel = new JPanel();
    JLabel label4 = new JLabel("Width Control:", JLabel.RIGHT);
    slider8 = createSlider(widthPanel, JSlider.HORIZONTAL, 0, 200, 100, 100, 10);
    slider8.addChangeListener(new SliderListener());

    widthPanel.setLayout(new GridLayout(1, 2));
    widthPanel.add(label4);
    widthPanel.add(slider8);
    getContentPane().add(widthPanel, BorderLayout.SOUTH);

    getContentPane().add(canvas);

    setSize(500, 500);
    setVisible(true);
}

From source file:DatabaseTest.java

public DatabaseTest() {
    super("Database Test Frame");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(350, 200);/*from   w  w  w. j  a  v a 2 s.  c  o  m*/

    qtm = new QueryTableModel();
    JTable table = new JTable(qtm);
    JScrollPane scrollpane = new JScrollPane(table);
    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(3, 2));
    p1.add(new JLabel("Enter the Host URL: "));
    p1.add(hostField = new JTextField());
    p1.add(new JLabel("Enter your query: "));
    p1.add(queryField = new JTextField());
    p1.add(new JLabel("Click here to send: "));

    JButton jb = new JButton("Search");
    jb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            qtm.setHostURL(hostField.getText().trim());
            qtm.setQuery(queryField.getText().trim());
        }
    });
    p1.add(jb);
    getContentPane().add(p1, BorderLayout.NORTH);
    getContentPane().add(scrollpane, BorderLayout.CENTER);
}

From source file:biomine.bmvis2.pipeline.EdgeLabelOperation.java

public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) {
    JPanel ret = new JPanel();
    ret.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = c.HORIZONTAL;//from w  w  w. j av a 2s. c  om
    c.weightx = 1;
    c.weighty = 0;
    c.gridy = 0;
    final Set<String> avail = graph.getAvailableEdgeLabels();

    for (final String str : avail) {
        final JCheckBox box = new JCheckBox();
        box.setSelected(enabledLabels.contains(str));
        box.setAction(new AbstractAction(str) {
            public void actionPerformed(ActionEvent arg0) {
                if (box.isSelected() != enabledLabels.contains(str)) {
                    if (box.isSelected())
                        enabledLabels.add(str);
                    else
                        enabledLabels.remove(str);
                    v.settingsChanged(false);
                }
            }
        });
        ret.add(box, c);
        c.gridy++;
    }

    return ret;
}

From source file:edu.stanford.smi.protegex.owl.ui.widget.HTMLEditorPanel.java

public HTMLEditorPanel(OWLModel owlModel, String text, String language) {
    setLayout(new BorderLayout());
    ekitCore = new EkitCore(null, null, null, null, false, true, true, null, null, false, false);
    ekitCore.setDocumentText(text);//from   w w w  .  j  a  v a  2  s.com
    JPanel ekitTopPanel = new JPanel();
    ekitTopPanel.setLayout(new GridLayout(2, 1));
    ekitTopPanel.add(ekitCore.getMenuBar());
    ekitTopPanel.add(ekitCore.getToolBar(true));
    if (owlModel != null) {
        languageComboBox = ComponentUtil.createLanguageComboBox(owlModel, language);
        Box languagePanel = Box.createHorizontalBox();
        languagePanel.add(new JLabel("Language: "));
        languagePanel.add(languageComboBox);
        add(BorderLayout.SOUTH, languagePanel);
    }
    add(BorderLayout.NORTH, ekitTopPanel);
    add(BorderLayout.CENTER, ekitCore);
}

From source file:gui.SignUpGUI.java

public SignUpGUI() {
    super("Sign Up");
    setResizable(false);/*ww  w. j a  v a 2  s. com*/
    setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
    setSize(500, 250);
    JPanel panelServer = new JPanel();
    addComponentToPanel(panelServer, labelServer, textFieldServer);
    add(panelServer);
    JPanel panelPort = new JPanel();
    addComponentToPanel(panelPort, labelPort, textFieldPort);
    add(panelPort);
    JPanel panelID = new JPanel();
    addComponentToPanel(panelID, labelID, textFieldID);
    add(panelID);
    JPanel panelPassword = new JPanel();
    pwdFieldPwd.setEchoChar('*');
    pwdFieldConfirmPwd.setEchoChar('*');
    addComponentToPanel(panelPassword, labelPassword, pwdFieldPwd);
    add(panelPassword);
    JPanel panelConfirmPwd = new JPanel();
    addComponentToPanel(panelConfirmPwd, labelConfirmPwd, pwdFieldConfirmPwd);
    add(panelConfirmPwd);
    JPanel panelNickname = new JPanel();
    addComponentToPanel(panelNickname, labelNickname, textFieldNickname);
    add(panelNickname);
    JPanel panelButton = new JPanel();
    panelButton.setLayout(new FlowLayout());
    buttonSignUp.addActionListener(new SignUpActionListener());
    panelButton.add(buttonSignUp);
    add(panelButton);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setVisible(true);
}

From source file:Ellipse.java

public Ellipse() {
    super();/* ww w. j  av  a  2  s .co m*/
    Container container = getContentPane();

    canvas = new DrawingCanvas();
    container.add(canvas);

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(1, 2));
    panel.add(new JLabel("x,y: ", JLabel.RIGHT));
    location = new JLabel("");
    panel.add(location);

    container.add(panel, BorderLayout.SOUTH);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    setSize(600, 300);
    setVisible(true);
}

From source file:layout.FlowLayoutDemo.java

public void addComponentsToPane(final Container pane) {
    final JPanel compsToExperiment = new JPanel();
    compsToExperiment.setLayout(experimentLayout);
    experimentLayout.setAlignment(FlowLayout.TRAILING);
    JPanel controls = new JPanel();
    controls.setLayout(new FlowLayout());

    LtoRbutton = new JRadioButton(LtoR);
    LtoRbutton.setActionCommand(LtoR);/*from w  w w.  j a  va  2s  .  c om*/
    LtoRbutton.setSelected(true);
    RtoLbutton = new JRadioButton(RtoL);
    RtoLbutton.setActionCommand(RtoL);

    //Add buttons to the experiment layout
    compsToExperiment.add(new JButton("Button 1"));
    compsToExperiment.add(new JButton("Button 2"));
    compsToExperiment.add(new JButton("Button 3"));
    compsToExperiment.add(new JButton("Long-Named Button 4"));
    compsToExperiment.add(new JButton("5"));
    //Left to right component orientation is selected by default
    compsToExperiment.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);

    //Add controls to set up the component orientation in the experiment layout
    final ButtonGroup group = new ButtonGroup();
    group.add(LtoRbutton);
    group.add(RtoLbutton);
    controls.add(LtoRbutton);
    controls.add(RtoLbutton);
    controls.add(applyButton);

    //Process the Apply component orientation button press
    applyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String command = group.getSelection().getActionCommand();
            //Check the selection
            if (command.equals("Left to right")) {
                compsToExperiment.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
            } else {
                compsToExperiment.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
            }
            //update the experiment layout
            compsToExperiment.validate();
            compsToExperiment.repaint();
        }
    });
    pane.add(compsToExperiment, BorderLayout.CENTER);
    pane.add(controls, BorderLayout.SOUTH);
    ;
}

From source file:net.ontopia.topicmaps.viz.AboutFrame.java

public AboutFrame(Frame parent) {
    super(parent, Messages.getString("Viz.About", "Ontopia Vizigator"), true);

    JPanel mainPanel = new JPanel();
    mainPanel.setBackground(Color.white);
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    mainPanel.add(createImagePanel());/*w w  w.j  a  va 2  s  .c  o m*/
    mainPanel.add(createAboutTextPanel());

    this.getContentPane().add(mainPanel);
    this.pack();
    this.setResizable(false);
    //    Center the dialog box above its parent
    this.setLocation((parent.getX() + (parent.getWidth() - this.getWidth()) / 2),
            parent.getY() + (parent.getHeight() - this.getHeight()) / 2);
}

From source file:ConvolveApp.java

public ConvolveApp() {
    super();/*  www.  j av  a2  s.  c  o m*/
    Container container = getContentPane();

    displayPanel = new CPanel();
    container.add(displayPanel);

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(2, 2));
    panel.setBorder(new TitledBorder("Click a Button to Perform the Associated Operation and Reset..."));

    sharpenButton = new JButton("Sharpen");
    sharpenButton.addActionListener(new ButtonListener());
    blurringButton = new JButton("Blur");
    blurringButton.addActionListener(new ButtonListener());
    edButton = new JButton("Edge Detect");
    edButton.addActionListener(new ButtonListener());
    resetButton = new JButton("Reset");
    resetButton.addActionListener(new ButtonListener());

    panel.add(sharpenButton);
    panel.add(blurringButton);
    panel.add(edButton);
    panel.add(resetButton);

    container.add(BorderLayout.SOUTH, panel);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    setSize(displayPanel.getWidth(), displayPanel.getHeight() + 10);
    setVisible(true);
}