List of usage examples for java.awt GridBagLayout GridBagLayout
public GridBagLayout()
From source file:GridBagLayoutTest.java
public FontFrame() { setTitle("GridBagLayoutTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); GridBagLayout layout = new GridBagLayout(); setLayout(layout);/* w ww .j av a 2 s . com*/ ActionListener listener = new FontAction(); // construct components JLabel faceLabel = new JLabel("Face: "); face = new JComboBox(new String[] { "Serif", "SansSerif", "Monospaced", "Dialog", "DialogInput" }); face.addActionListener(listener); JLabel sizeLabel = new JLabel("Size: "); size = new JComboBox(new String[] { "8", "10", "12", "15", "18", "24", "36", "48" }); size.addActionListener(listener); bold = new JCheckBox("Bold"); bold.addActionListener(listener); italic = new JCheckBox("Italic"); italic.addActionListener(listener); sample = new JTextArea(); sample.setText("The quick brown fox jumps over the lazy dog"); sample.setEditable(false); sample.setLineWrap(true); sample.setBorder(BorderFactory.createEtchedBorder()); // add components to grid, using GBC convenience class add(faceLabel, new GBC(0, 0).setAnchor(GBC.EAST)); add(face, new GBC(1, 0).setFill(GBC.HORIZONTAL).setWeight(100, 0).setInsets(1)); add(sizeLabel, new GBC(0, 1).setAnchor(GBC.EAST)); add(size, new GBC(1, 1).setFill(GBC.HORIZONTAL).setWeight(100, 0).setInsets(1)); add(bold, new GBC(0, 2, 2, 1).setAnchor(GBC.CENTER).setWeight(100, 100)); add(italic, new GBC(0, 3, 2, 1).setAnchor(GBC.CENTER).setWeight(100, 100)); add(sample, new GBC(2, 0, 1, 4).setFill(GBC.BOTH).setWeight(100, 100)); }
From source file:fll.scheduler.ChooseChallengeDescriptor.java
private void initComponents() { getContentPane().setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.weightx = 1;//from w w w . j a v a2 s .c o m gbc.weighty = 1; gbc.fill = GridBagConstraints.BOTH; final JTextArea instructions = new JTextArea( "Choose a challenge description from the drop down list OR choose a file containing your custom challenge description.", 3, 40); instructions.setEditable(false); instructions.setWrapStyleWord(true); instructions.setLineWrap(true); getContentPane().add(instructions, gbc); gbc = new GridBagConstraints(); mCombo = new JComboBox<DescriptionInfo>(); gbc.gridwidth = GridBagConstraints.REMAINDER; getContentPane().add(mCombo, gbc); mCombo.setRenderer(new DescriptionInfoRenderer()); mCombo.setEditable(false); final List<DescriptionInfo> descriptions = DescriptionInfo.getAllKnownChallengeDescriptionInfo(); for (final DescriptionInfo info : descriptions) { mCombo.addItem(info); } mFileField = new JLabel(); gbc = new GridBagConstraints(); gbc.weightx = 1; getContentPane().add(mFileField, gbc); final JButton chooseButton = new JButton("Choose File"); gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; getContentPane().add(chooseButton, gbc); chooseButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent ae) { mFileField.setText(null); final JFileChooser fileChooser = new JFileChooser(); final FileFilter filter = new BasicFileFilter("FLL Description (xml)", new String[] { "xml" }); fileChooser.setFileFilter(filter); final int returnVal = fileChooser.showOpenDialog(ChooseChallengeDescriptor.this); if (returnVal == JFileChooser.APPROVE_OPTION) { final File selectedFile = fileChooser.getSelectedFile(); mFileField.setText(selectedFile.getAbsolutePath()); } } }); final Box buttonPanel = new Box(BoxLayout.X_AXIS); gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; getContentPane().add(buttonPanel, gbc); buttonPanel.add(Box.createHorizontalGlue()); final JButton ok = new JButton("Ok"); buttonPanel.add(ok); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent ae) { // use the selected description if nothing is entered in the file box final DescriptionInfo descriptionInfo = mCombo.getItemAt(mCombo.getSelectedIndex()); if (null != descriptionInfo) { mSelected = descriptionInfo.getURL(); } final String text = mFileField.getText(); if (!StringUtils.isEmpty(text)) { final File file = new File(text); if (file.exists()) { try { mSelected = file.toURI().toURL(); } catch (final MalformedURLException e) { throw new FLLInternalException("Can't turn file into URL?", e); } } } setVisible(false); } }); final JButton cancel = new JButton("Cancel"); buttonPanel.add(cancel); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent ae) { mSelected = null; setVisible(false); } }); pack(); }
From source file:events.TreeExpandEventDemo.java
public TreeExpandEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0;//w w w .jav a2s. c om c.weighty = 1.0; c.insets = new Insets(1, 1, 1, 1); demoArea = new DemoArea(); gridbag.setConstraints(demoArea, c); add(demoArea); c.insets = new Insets(0, 0, 0, 0); textArea = new JTextArea(); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setPreferredSize(new Dimension(200, 75)); gridbag.setConstraints(scrollPane, c); add(scrollPane); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:org.wsm.database.tools.editor.ui.GraphPane.java
public GraphPane() { GridBagLayout gbl = new GridBagLayout(); this.setLayout(gbl); this.qesi = new QueryExecStatsInfo(); this.qesi.addPropertyChangeListener(this); dcd = new DefaultCategoryDataset(); JFreeChart chart = getChart(CHART_TYPE_BAR_3D); chart.setBackgroundPaint(Color.white); cp = new ChartPanel(chart); cp.setBorder(BorderFactory.createTitledBorder(null, "Graph", TitledBorder.LEADING, TitledBorder.TOP, UIConstants.LABEL_FONT));//from w w w .ja v a 2 s . c o m cp.setMouseZoomable(true, true); //cp.setPreferredSize(new Dimension(700, 500)); gbl.setConstraints(cp, SwingUtils.getGridBagConstraints(0, 0, 2, 1)); this.add(cp); JPanel graphTypeSelectionPanel = new JPanel(); viewBarGraph = new JRadioButton("View Bar Graph", true); viewLineGraph = new JRadioButton("View Line Graph", false); viewLineGraph.setEnabled(false); ButtonGroup bg = new ButtonGroup(); bg.add(viewBarGraph); bg.add(viewLineGraph); GridBagLayout graphTypeGBL = new GridBagLayout(); graphTypeSelectionPanel.setLayout(graphTypeGBL); graphTypeGBL.setConstraints(viewBarGraph, SwingUtils.getGridBagConstraints(0, 0)); graphTypeGBL.setConstraints(viewLineGraph, SwingUtils.getGridBagConstraints(1, 0)); graphTypeSelectionPanel.add(viewBarGraph); graphTypeSelectionPanel.add(viewLineGraph); viewBarGraph.addActionListener(this); viewLineGraph.addActionListener(this); graphTypeSelectionPanel.setBorder(BorderFactory.createTitledBorder(null, "Graph Type", TitledBorder.LEADING, TitledBorder.TOP, UIConstants.LABEL_FONT)); gbl.setConstraints(graphTypeSelectionPanel, SwingUtils.getGridBagConstraints(0, 1, 2, 1)); this.add(graphTypeSelectionPanel); //this.setBounds(50, 100, 100, 200); this.setBackground(Color.WHITE); }
From source file:com.microsoft.alm.plugin.idea.common.ui.controls.HelpPanel.java
public HelpPanel() { // Create controls helpLabel = new JLabel(); final IconPanel helpIcon = new IconPanel(Icons.Help); // Layout controls setLayout(new GridBagLayout()); SwingHelper.addToGridBag(this, helpLabel, 0, 0, 1, 1, 0, JBUI.scale(4)); SwingHelper.addToGridBag(this, helpIcon, 1, 0); this.addMouseListener(new MouseEventListener()); showTooltipTimer = new Timer(INITIAL_DELAY, new ActionListener() { @Override//from ww w . jav a 2 s . co m public void actionPerformed(final ActionEvent e) { IdeaHelper.runOnUIThread(new Runnable() { @Override public void run() { showToolTip(true); } }); } }); showTooltipTimer.setInitialDelay(INITIAL_DELAY); showTooltipTimer.setRepeats(false); hideTooltipTimer = new Timer(DISMISS_DELAY, new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { IdeaHelper.runOnUIThread(new Runnable() { @Override public void run() { hideToolTip(true); } }); } }); hideTooltipTimer.setInitialDelay(DISMISS_DELAY); hideTooltipTimer.setRepeats(false); }
From source file:tl.lib.dataCollection.gui.MultipleChartsPanel.java
public MultipleChartsPanel(_CollectionGUIScenario scenario, String label, String description) { super(new GridBagLayout()); this.charts = new Hashtable<Integer, _ChartPanel>(); this.scenario = scenario; this.description = description; this.label = label; grid = new GridBagConstraints(); grid.weighty = 1;/* w w w . j a v a 2 s . c o m*/ grid.weightx = 1; grid.anchor = GridBagConstraints.PAGE_START; grid.fill = GridBagConstraints.BOTH; }
From source file:com.game.ui.views.PlayerEditor.java
public void doGui() { // setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setLayout(new GridBagLayout()); GridBagConstraints c1 = new GridBagConstraints(); c1.fill = GridBagConstraints.NONE; c1.anchor = GridBagConstraints.WEST; c1.insets = new Insets(10, 5, 10, 5); c1.weightx = 0;/*from w ww . j a v a2 s . c o m*/ c1.weighty = 0; JLabel noteLbl = new JLabel("Pls select a value to choose a Player or you can create a new " + "Player entity below. Once selected a Player character, its' details will be available below"); add(noteLbl, c1); DefaultComboBoxModel model = new DefaultComboBoxModel(); for (GameCharacter character : GameBean.playerDetails) { model.addElement(((Player) character).getType()); } c1.gridy = 1; comboBox = new JComboBox(model); comboBox.setSelectedIndex(-1); comboBox.setMaximumSize(new Dimension(100, 30)); comboBox.setActionCommand("dropDown"); comboBox.addActionListener(this); add(comboBox, c1); JPanel wrapperPanel = new JPanel(new GridLayout(1, 2, 10, 10)); wrapperPanel.setBorder(LineBorder.createGrayLineBorder()); leftPanel = new JPanel(); leftPanel.setAlignmentX(0); leftPanel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(5, 5, 5, 5); c.weightx = 1; c.weighty = 1; c.gridwidth = 2; JLabel enemyDtlLbl = new JLabel("Enemy Character Details : "); enemyDtlLbl.setFont(new Font("Times New Roman", Font.BOLD, 15)); leftPanel.add(enemyDtlLbl, c); c.gridwidth = 1; c.gridy = 1; JLabel nameLbl = new JLabel("Name : "); leftPanel.add(nameLbl, c); c.gridx = 1; JTextField name = new JTextField(""); name.setColumns(20); leftPanel.add(name, c); c.gridx = 0; c.gridy = 2; JLabel imageLbl = new JLabel("Image Path : "); leftPanel.add(imageLbl, c); c.gridx = 1; JTextField image = new JTextField(""); image.setColumns(20); leftPanel.add(image, c); c.gridx = 0; c.gridy = 3; JLabel healthLbl = new JLabel("Health Pts : "); leftPanel.add(healthLbl, c); c.gridx = 1; JTextField health = new JTextField(""); health.setColumns(20); leftPanel.add(health, c); c.gridx = 0; c.gridy = 4; JLabel attackPtsLbl = new JLabel("Attack Points : "); leftPanel.add(attackPtsLbl, c); c.gridx = 1; JTextField attackPts = new JTextField(""); attackPts.setColumns(20); leftPanel.add(attackPts, c); c.gridx = 0; c.gridy = 5; JLabel armoursPtsLbl = new JLabel("Armour Points : "); leftPanel.add(armoursPtsLbl, c); c.gridx = 1; JTextField armourPts = new JTextField(""); armourPts.setColumns(20); leftPanel.add(armourPts, c); c.gridx = 0; c.gridy = 6; JLabel attackRngeLbl = new JLabel("Attack Range : "); leftPanel.add(attackRngeLbl, c); c.gridx = 1; JTextField attackRnge = new JTextField(""); attackRnge.setColumns(20); leftPanel.add(attackRnge, c); c.gridx = 0; c.gridy = 7; JLabel movementLbl = new JLabel("Movement : "); leftPanel.add(movementLbl, c); c.gridx = 1; JTextField movement = new JTextField(""); movement.setColumns(20); leftPanel.add(movement, c); c.gridx = 0; c.gridy = 8; JLabel typeLbl = new JLabel("Type : "); leftPanel.add(typeLbl, c); c.gridx = 1; JTextField typeTxt = new JTextField(""); typeTxt.setColumns(20); leftPanel.add(typeTxt, c); c.gridx = 0; c.gridy = 9; JLabel weaponLbl = new JLabel("Equipped Weapon : "); leftPanel.add(weaponLbl, c); c.gridx = 1; DefaultComboBoxModel weapon = new DefaultComboBoxModel(); for (Item item : GameBean.weaponDetails) { if (item instanceof Weapon) { weapon.addElement(((Weapon) item).getName()); } } JComboBox weaponDrpDown = new JComboBox(weapon); weaponDrpDown.setSelectedIndex(-1); weaponDrpDown.setMaximumSize(new Dimension(100, 30)); leftPanel.add(weaponDrpDown, c); c.gridx = 0; c.gridy = 10; c.gridwidth = 2; JButton submit = new JButton("Save"); submit.addActionListener(this); submit.setActionCommand("button"); leftPanel.add(submit, c); wrapperPanel.add(leftPanel); lvlPanel = new LevelPanel(true, null); wrapperPanel.add(lvlPanel); c1.gridy = 2; c1.fill = GridBagConstraints.BOTH; add(wrapperPanel, c1); c1.fill = GridBagConstraints.NONE; validationMess = new JLabel("Pls enter all the fields or pls choose a character from the drop down"); validationMess.setForeground(Color.red); validationMess.setVisible(false); c1.gridy = 3; add(validationMess, c1); c1.weightx = 1; c1.fill = GridBagConstraints.BOTH; c1.weighty = 1; c1.gridy = 4; add(new JPanel(), c1); }
From source file:be.ac.ua.comp.scarletnebula.gui.AllGraphsPanel.java
/** * Constructor./* w w w.j a v a 2 s.c o m*/ * * @param server * The server whose statistics to display. */ public AllGraphsPanel(final Server server) { super(new GridBagLayout()); this.server = server; statisticsManager = server.getServerStatistics(); statisticsManager.addNewDatastreamListener(this); statisticsManager.addDeleteDatastreamListener(this); setOpaque(true); setBackground(Color.WHITE); setBorder(BorderFactory.createEtchedBorder()); placeComponents(); }
From source file:QueryDB.java
public QueryDBFrame() { setTitle("QueryDB"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); setLayout(new GridBagLayout()); authors = new JComboBox(); authors.setEditable(false);/* www .j av a 2 s . com*/ authors.addItem("Any"); publishers = new JComboBox(); publishers.setEditable(false); publishers.addItem("Any"); result = new JTextArea(4, 50); result.setEditable(false); priceChange = new JTextField(8); priceChange.setText("-5.00"); try { conn = getConnection(); Statement stat = conn.createStatement(); String query = "SELECT Name FROM Authors"; ResultSet rs = stat.executeQuery(query); while (rs.next()) authors.addItem(rs.getString(1)); rs.close(); query = "SELECT Name FROM Publishers"; rs = stat.executeQuery(query); while (rs.next()) publishers.addItem(rs.getString(1)); rs.close(); stat.close(); } catch (SQLException e) { for (Throwable t : e) result.append(t.getMessage()); } catch (IOException e) { result.setText("" + e); } // we use the GBC convenience class of Core Java Volume 1 Chapter 9 add(authors, new GBC(0, 0, 2, 1)); add(publishers, new GBC(2, 0, 2, 1)); JButton queryButton = new JButton("Query"); queryButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { executeQuery(); } }); add(queryButton, new GBC(0, 1, 1, 1).setInsets(3)); JButton changeButton = new JButton("Change prices"); changeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { changePrices(); } }); add(changeButton, new GBC(2, 1, 1, 1).setInsets(3)); add(priceChange, new GBC(3, 1, 1, 1).setFill(GBC.HORIZONTAL)); add(new JScrollPane(result), new GBC(0, 2, 4, 1).setFill(GBC.BOTH).setWeight(100, 100)); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { try { if (conn != null) conn.close(); } catch (SQLException e) { for (Throwable t : e) t.printStackTrace(); } } }); }
From source file:MultipartViewer.java
public MultipartViewer() { super(new GridBagLayout()); }