List of usage examples for java.awt Container setComponentOrientation
public void setComponentOrientation(ComponentOrientation o)
From source file:GridLayoutDemo.java
public static void addComponentsToPane(Container pane) { if (RIGHT_TO_LEFT) { pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); }//from w w w. ja v a 2 s. co m pane.setLayout(new GridLayout(0, 2)); pane.add(new JButton("Button 1")); pane.add(new JButton("Button 2")); pane.add(new JButton("Button 3")); pane.add(new JButton("Long-Named Button 4")); pane.add(new JButton("5")); }
From source file:GridBagLayoutDemo.java
public static void addComponentsToPane(Container pane) { if (RIGHT_TO_LEFT) { pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); }//from ww w . j a va 2 s . c o m JButton button; pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); if (shouldFill) { // natural height, maximum width c.fill = GridBagConstraints.HORIZONTAL; } button = new JButton("Button 1"); if (shouldWeightX) { c.weightx = 0.5; } c.gridx = 0; c.gridy = 0; pane.add(button, c); button = new JButton("Button 2"); c.gridx = 1; c.gridy = 0; pane.add(button, c); button = new JButton("Button 3"); c.gridx = 2; c.gridy = 0; pane.add(button, c); button = new JButton("Long-Named Button 4"); c.ipady = 40; // make this component tall c.weightx = 0.0; c.gridwidth = 3; c.gridx = 0; c.gridy = 1; pane.add(button, c); button = new JButton("5"); c.ipady = 0; // reset to default c.weighty = 1.0; // request any extra vertical space c.anchor = GridBagConstraints.PAGE_END; // bottom of space c.insets = new Insets(10, 0, 0, 0); // top padding c.gridx = 1; // aligned with button 2 c.gridwidth = 2; // 2 columns wide c.gridy = 2; // third row pane.add(button, c); }
From source file:layout.GridBagLayoutDemo.java
public static void addComponentsToPane(Container pane) { if (RIGHT_TO_LEFT) { pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); }/*from w w w .ja v a 2 s.c o m*/ JButton button; pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); if (shouldFill) { //natural height, maximum width c.fill = GridBagConstraints.HORIZONTAL; } button = new JButton("Button 1"); if (shouldWeightX) { c.weightx = 0.5; } c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; pane.add(button, c); button = new JButton("Button 2"); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.5; c.gridx = 1; c.gridy = 0; pane.add(button, c); button = new JButton("Button 3"); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.5; c.gridx = 2; c.gridy = 0; pane.add(button, c); button = new JButton("Long-Named Button 4"); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 40; //make this component tall c.weightx = 0.0; c.gridwidth = 3; c.gridx = 0; c.gridy = 1; pane.add(button, c); button = new JButton("5"); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 0; //reset to default c.weighty = 1.0; //request any extra vertical space c.anchor = GridBagConstraints.PAGE_END; //bottom of space c.insets = new Insets(10, 0, 0, 0); //top padding c.gridx = 1; //aligned with button 2 c.gridwidth = 2; //2 columns wide c.gridy = 2; //third row pane.add(button, c); }
From source file:layout.BorderLayoutDemo.java
public static void addComponentsToPane(Container pane) { if (!(pane.getLayout() instanceof BorderLayout)) { pane.add(new JLabel("Container doesn't use BorderLayout!")); return;/*from w ww .ja v a 2 s . c o m*/ } if (RIGHT_TO_LEFT) { pane.setComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT); } JButton button = new JButton("Button 1 (PAGE_START)"); pane.add(button, BorderLayout.PAGE_START); //Make the center component big, since that's the //typical usage of BorderLayout. button = new JButton("Button 2 (CENTER)"); button.setPreferredSize(new Dimension(200, 100)); pane.add(button, BorderLayout.CENTER); button = new JButton("Button 3 (LINE_START)"); pane.add(button, BorderLayout.LINE_START); button = new JButton("Long-Named Button 4 (PAGE_END)"); pane.add(button, BorderLayout.PAGE_END); button = new JButton("5 (LINE_END)"); pane.add(button, BorderLayout.LINE_END); }
From source file:com.oracle.tutorial.jdbc.CoffeesFrame.java
public CoffeesFrame(JDBCTutorialUtilities settingsArg) throws SQLException { super("The Coffee Break: COFFEES Table"); // Set window title this.settings = settingsArg; connection = settings.getConnection(); // Close connections exit the application when the user // closes the window addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { try { connection.close();/*from ww w. j a v a 2s . c om*/ } catch (SQLException sqle) { JDBCTutorialUtilities.printSQLException(sqle); } System.exit(0); } }); // Initialize and lay out window controls CachedRowSet myCachedRowSet = getContentsOfCoffeesTable(); myCoffeesTableModel = new CoffeesTableModel(myCachedRowSet); myCoffeesTableModel.addEventHandlersToRowSet(this); table = new JTable(); // Displays the table table.setModel(myCoffeesTableModel); label_COF_NAME = new JLabel(); label_SUP_ID = new JLabel(); label_PRICE = new JLabel(); label_SALES = new JLabel(); label_TOTAL = new JLabel(); textField_COF_NAME = new JTextField(10); textField_SUP_ID = new JTextField(10); textField_PRICE = new JTextField(10); textField_SALES = new JTextField(10); textField_TOTAL = new JTextField(10); button_ADD_ROW = new JButton(); button_UPDATE_DATABASE = new JButton(); button_DISCARD_CHANGES = new JButton(); label_COF_NAME.setText("Coffee Name:"); label_SUP_ID.setText("Supplier ID:"); label_PRICE.setText("Price:"); label_SALES.setText("Sales:"); label_TOTAL.setText("Total Sales:"); textField_COF_NAME.setText("Enter new coffee name"); textField_SUP_ID.setText("101"); textField_PRICE.setText("0"); textField_SALES.setText("0"); textField_TOTAL.setText("0"); button_ADD_ROW.setText("Add row to table"); button_UPDATE_DATABASE.setText("Update database"); button_DISCARD_CHANGES.setText("Discard changes"); // Place the components within the container contentPane; use GridBagLayout // as the layout. Container contentPane = getContentPane(); contentPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); contentPane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.CENTER; c.weightx = 0.5; c.weighty = 1.0; c.gridx = 0; c.gridy = 0; c.gridwidth = 2; contentPane.add(new JScrollPane(table), c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.25; c.weighty = 0; c.gridx = 0; c.gridy = 1; c.gridwidth = 1; contentPane.add(label_COF_NAME, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.75; c.weighty = 0; c.gridx = 1; c.gridy = 1; c.gridwidth = 1; contentPane.add(textField_COF_NAME, c); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.25; c.weighty = 0; c.anchor = GridBagConstraints.LINE_START; c.gridx = 0; c.gridy = 2; c.gridwidth = 1; contentPane.add(label_SUP_ID, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.75; c.weighty = 0; c.gridx = 1; c.gridy = 2; c.gridwidth = 1; contentPane.add(textField_SUP_ID, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.25; c.weighty = 0; c.gridx = 0; c.gridy = 3; c.gridwidth = 1; contentPane.add(label_PRICE, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.75; c.weighty = 0; c.gridx = 1; c.gridy = 3; c.gridwidth = 1; contentPane.add(textField_PRICE, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.25; c.weighty = 0; c.gridx = 0; c.gridy = 4; c.gridwidth = 1; contentPane.add(label_SALES, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.75; c.weighty = 0; c.gridx = 1; c.gridy = 4; c.gridwidth = 1; contentPane.add(textField_SALES, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.25; c.weighty = 0; c.gridx = 0; c.gridy = 5; c.gridwidth = 1; contentPane.add(label_TOTAL, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.75; c.weighty = 0; c.gridx = 1; c.gridy = 5; c.gridwidth = 1; contentPane.add(textField_TOTAL, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.5; c.weighty = 0; c.gridx = 0; c.gridy = 6; c.gridwidth = 1; contentPane.add(button_ADD_ROW, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.5; c.weighty = 0; c.gridx = 1; c.gridy = 6; c.gridwidth = 1; contentPane.add(button_UPDATE_DATABASE, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.5; c.weighty = 0; c.gridx = 0; c.gridy = 7; c.gridwidth = 1; contentPane.add(button_DISCARD_CHANGES, c); // Add listeners for the buttons in the application button_ADD_ROW.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(CoffeesFrame.this, new String[] { "Adding the following row:", "Coffee name: [" + textField_COF_NAME.getText() + "]", "Supplier ID: [" + textField_SUP_ID.getText() + "]", "Price: [" + textField_PRICE.getText() + "]", "Sales: [" + textField_SALES.getText() + "]", "Total: [" + textField_TOTAL.getText() + "]" }); try { myCoffeesTableModel.insertRow(textField_COF_NAME.getText(), Integer.parseInt(textField_SUP_ID.getText().trim()), Float.parseFloat(textField_PRICE.getText().trim()), Integer.parseInt(textField_SALES.getText().trim()), Integer.parseInt(textField_TOTAL.getText().trim())); } catch (SQLException sqle) { displaySQLExceptionDialog(sqle); } } }); button_UPDATE_DATABASE.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { myCoffeesTableModel.coffeesRowSet.acceptChanges(); } catch (SQLException sqle) { displaySQLExceptionDialog(sqle); // Now revert back changes try { createNewTableModel(); } catch (SQLException sqle2) { displaySQLExceptionDialog(sqle2); } } } }); button_DISCARD_CHANGES.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { createNewTableModel(); } catch (SQLException sqle) { displaySQLExceptionDialog(sqle); } } }); }