List of usage examples for javax.swing SpringLayout SpringLayout
public SpringLayout()
SpringLayout
. From source file:SpringDemo3.java
public static void main(String[] args) { JFrame frame = new JFrame("SpringDemo3"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout);//from w w w . j av a 2 s . co m // Create and add the components. JLabel label = new JLabel("Label: "); JTextField textField = new JTextField("Text field", 15); contentPane.add(label); contentPane.add(textField); // Adjust constraints for the label so it's at (5,5). layout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, contentPane); layout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, contentPane); // Adjust constraints for the text field so it's at // (<label's right edge> + 5, 5). layout.putConstraint(SpringLayout.WEST, textField, 5, SpringLayout.EAST, label); layout.putConstraint(SpringLayout.NORTH, textField, 5, SpringLayout.NORTH, contentPane); // Adjust constraints for the content pane: Its right // edge should be 5 pixels beyond the text field's right // edge, and its bottom edge should be 5 pixels beyond // the bottom edge of the tallest component (which we'll // assume is textField). layout.putConstraint(SpringLayout.EAST, contentPane, 5, SpringLayout.EAST, textField); layout.putConstraint(SpringLayout.SOUTH, contentPane, 5, SpringLayout.SOUTH, textField); // Display the window. frame.pack(); frame.setVisible(true); }
From source file:SpringDemo4.java
public static void main(String[] args) { JFrame frame = new JFrame("SpringDemo4"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout);//from w w w .j a v a 2s. c o m // Create and add the components. JLabel label = new JLabel("Label: "); JTextField textField = new JTextField("Text field", 15); contentPane.add(label); contentPane.add(textField); // Adjust constraints for the label so it's at (5,5). SpringLayout.Constraints labelCons = layout.getConstraints(label); labelCons.setX(Spring.constant(5)); labelCons.setY(Spring.constant(5)); // Adjust constraints for the text field so it's at // (<label's right edge> + 5, 5). SpringLayout.Constraints textFieldCons = layout.getConstraints(textField); textFieldCons.setX(Spring.sum(Spring.constant(5), labelCons.getConstraint(SpringLayout.EAST))); textFieldCons.setY(Spring.constant(5)); // Adjust constraints for the content pane. setContainerSize(contentPane, 5); // Display the window. frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public SpringLayoutPanel() { SpringLayout layout = new SpringLayout(); setLayout(layout);/* ww w. j a v a 2s. c o m*/ JButton[] buttons = new JButton[6]; for (int i = 0; i < buttons.length; i++) { buttons[i] = new JButton("Press " + (i + 1)); add(buttons[i]); } Spring xSpring = Spring.constant(5, 15, 25); Spring ySpring = Spring.constant(10, 30, 50); Spring wSpring = Spring.constant(30, 80, 130); SpringLayout.Constraints buttonConstr = layout.getConstraints(buttons[0]); buttonConstr.setX(xSpring); buttonConstr.setY(ySpring); for (int i = 0; i < buttons.length; i++) { buttonConstr = layout.getConstraints(buttons[i]); buttonConstr.setHeight(ySpring); buttonConstr.setWidth(wSpring); if (i > 0) { layout.putConstraint(SpringLayout.WEST, buttons[i], xSpring, SpringLayout.EAST, buttons[i - 1]); layout.putConstraint(SpringLayout.NORTH, buttons[i], ySpring, SpringLayout.SOUTH, buttons[i - 1]); } } SpringLayout.Constraints constr = layout.getConstraints(this); constr.setConstraint(SpringLayout.EAST, Spring.sum(buttonConstr.getConstraint(SpringLayout.EAST), Spring.constant(15))); constr.setConstraint(SpringLayout.SOUTH, Spring.sum(buttonConstr.getConstraint(SpringLayout.SOUTH), Spring.constant(10))); }
From source file:de.dakror.virtualhub.server.dialog.BackupEditDialog.java
public static void show() throws JSONException { final JDialog dialog = new JDialog(Server.currentServer.frame, "Backup-Einstellungen", true); dialog.setSize(400, 250);// w ww. j a v a2s . com dialog.setLocationRelativeTo(Server.currentServer.frame); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); JPanel cp = new JPanel(new SpringLayout()); cp.add(new JLabel("Zielverzeichnis:")); JPanel panel = new JPanel(); final JTextField path = new JTextField((Server.currentServer.settings.has("backup.path") ? Server.currentServer.settings.getString("backup.path") : ""), 10); panel.add(path); panel.add(new JButton(new AbstractAction("Whlen...") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { JFileChooser jfc = new JFileChooser((path.getText().length() > 0 ? new File(path.getText()) : new File(System.getProperty("user.home")))); jfc.setFileHidingEnabled(false); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setDialogTitle("Backup-Zielverzeichnis whlen"); if (jfc.showOpenDialog(dialog) == JFileChooser.APPROVE_OPTION) path.setText(jfc.getSelectedFile().getPath().replace("\\", "/")); } })); cp.add(panel); cp.add(new JLabel("")); cp.add(new JLabel("")); cp.add(new JButton(new AbstractAction("Abbrechen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } })); cp.add(new JButton(new AbstractAction("Speichern") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { try { if (path.getText().length() > 0) Server.currentServer.settings.put("backup.path", path.getText()); dialog.dispose(); } catch (JSONException e1) { e1.printStackTrace(); } } })); SpringUtilities.makeCompactGrid(cp, 3, 2, 6, 6, 6, 6); dialog.setContentPane(cp); dialog.pack(); dialog.setVisible(true); }
From source file:layout.SpringGrid.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*from ww w . j a v a 2 s .c o m*/ */ private static void createAndShowGUI() { //Create the panel and populate it. JPanel panel = new JPanel(new SpringLayout()); for (int i = 0; i < 9; i++) { JTextField textField = new JTextField(Integer.toString(i)); //Make the 4th field extra big. if (i == 4) { textField.setText("This one is extra long."); } panel.add(textField); } //Lay out the panel. SpringUtilities.makeGrid(panel, 3, 3, //rows, cols 5, 5, //initialX, initialY 5, 5);//xPad, yPad //Create and set up the window. JFrame frame = new JFrame("SpringGrid"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. panel.setOpaque(true); //content panes must be opaque frame.setContentPane(panel); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:SpringCompactGrid.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*from ww w. j av a 2 s . co m*/ */ private static void createAndShowGUI() { JPanel panel = new JPanel(new SpringLayout()); int rows = 10; int cols = 10; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { int anInt = (int) Math.pow(r, c); JTextField textField = new JTextField(Integer.toString(anInt)); panel.add(textField); } } //Lay out the panel. SpringUtilities.makeCompactGrid(panel, //parent rows, cols, 3, 3, //initX, initY 3, 3); //xPad, yPad //Create and set up the window. JFrame frame = new JFrame("SpringCompactGrid"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. panel.setOpaque(true); //content panes must be opaque frame.setContentPane(panel); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:layout.SpringDemo1.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./* w ww.j av a 2s .co m*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("SpringDemo1"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout); contentPane.add(new JLabel("Label: ")); contentPane.add(new JTextField("Text field", 15)); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:layout.SpringDemo2.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*from w w w . j a v a2s .co m*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("SpringDemo2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout); //Create and add the components. JLabel label = new JLabel("Label: "); JTextField textField = new JTextField("Text field", 15); contentPane.add(label); contentPane.add(textField); //Adjust constraints for the label so it's at (5,5). layout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, contentPane); layout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, contentPane); //Adjust constraints for the text field so it's at //(<label's right edge> + 5, 5). layout.putConstraint(SpringLayout.WEST, textField, 5, SpringLayout.EAST, label); layout.putConstraint(SpringLayout.NORTH, textField, 5, SpringLayout.NORTH, contentPane); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:layout.SpringDemo3.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread.//from w ww.j a va2 s. c o m */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("SpringDemo3"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout); //Create and add the components. JLabel label = new JLabel("Label: "); JTextField textField = new JTextField("Text field", 15); contentPane.add(label); contentPane.add(textField); //Adjust constraints for the label so it's at (5,5). layout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, contentPane); layout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, contentPane); //Adjust constraints for the text field so it's at //(<label's right edge> + 5, 5). layout.putConstraint(SpringLayout.WEST, textField, 5, SpringLayout.EAST, label); layout.putConstraint(SpringLayout.NORTH, textField, 5, SpringLayout.NORTH, contentPane); //Adjust constraints for the content pane: Its right //edge should be 5 pixels beyond the text field's right //edge, and its bottom edge should be 5 pixels beyond //the bottom edge of the tallest component (which we'll //assume is textField). layout.putConstraint(SpringLayout.EAST, contentPane, 5, SpringLayout.EAST, textField); layout.putConstraint(SpringLayout.SOUTH, contentPane, 5, SpringLayout.SOUTH, textField); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:SpringForm.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread.//w w w . j a v a 2s.c o m */ private static void createAndShowGUI() { String[] labels = { "Name: ", "Fax: ", "Email: ", "Address: " }; int numPairs = labels.length; //Create and populate the panel. JPanel p = new JPanel(new SpringLayout()); for (int i = 0; i < numPairs; i++) { JLabel l = new JLabel(labels[i], JLabel.TRAILING); p.add(l); JTextField textField = new JTextField(10); l.setLabelFor(textField); p.add(textField); } //Lay out the panel. SpringUtilities.makeCompactGrid(p, numPairs, 2, //rows, cols 6, 6, //initX, initY 6, 6); //xPad, yPad //Create and set up the window. JFrame frame = new JFrame("SpringForm"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. p.setOpaque(true); //content panes must be opaque frame.setContentPane(p); //Display the window. frame.pack(); frame.setVisible(true); }