List of usage examples for javax.swing JTextField setColumns
@BeanProperty(bound = false, description = "the number of columns preferred for display") public void setColumns(int columns)
TextField
, and then invalidate the layout. From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); JPanel topPane = new JPanel(); JPanel midPane = new JPanel(); JPanel panesHolder = new JPanel(); JLabel label = new JLabel("Top label"); JTextField field = new JTextField(); field.setColumns(5); topPane.setLayout(new FlowLayout()); midPane.setLayout(new GridLayout(3, 2)); topPane.add(label);//from w ww .jav a 2 s.c o m topPane.add(field); midPane.add(new JButton("Button 1")); midPane.add(new JButton("Button 2")); midPane.add(new JButton("A")); midPane.add(new JButton("H")); midPane.add(new JButton("I")); midPane.add(new JButton("T")); panesHolder.setLayout(new BoxLayout(panesHolder, BoxLayout.Y_AXIS)); panesHolder.add(topPane); panesHolder.add(midPane); frame.add(panesHolder); frame.setSize(400, 300); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:de.codesourcery.geoip.Main.java
public static void main(String[] args) throws Exception { final IGeoLocator<StringSubject> locator = createGeoLocator(); final JFrame frame = new JFrame("GeoIP"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { try { locator.dispose();/*w w w . j av a 2 s . c o m*/ } catch (Exception e1) { e1.printStackTrace(); } }; }); final MapImage image = MapImage.getRobinsonWorldMap(); // MapImage.getMillerWorldMap(); final MapCanvas canvas = new MapCanvas(image); for (GeoLocation<StringSubject> loc : locator.locate(getSpammers())) { if (loc.hasValidCoordinates()) { canvas.addCoordinate(PointRenderer.createPoint(loc, Color.YELLOW)); } } // canvas.addCoordinate( PointRenderer.createPoint( ZERO , Color.YELLOW ) ); // canvas.addCoordinate( PointRenderer.createPoint( WELLINGTON , Color.RED ) ); // canvas.addCoordinate( PointRenderer.createPoint( MELBOURNE , Color.RED ) ); // canvas.addCoordinate( PointRenderer.createPoint( HAMBURG , Color.RED ) ); final double heightToWidth = image.height() / (double) image.width(); // preserve aspect ratio of map canvas.setPreferredSize(new Dimension(640, (int) Math.round(640 * heightToWidth))); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout()); panel.add(new JLabel("Scale-X")); final JTextField scaleX = new JTextField(Double.toString(image.getScaleX())); scaleX.setColumns(5); final JTextField scaleY = new JTextField(Double.toString(image.getScaleY())); scaleY.setColumns(5); final ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double x = Double.parseDouble(scaleX.getText()); double y = Double.parseDouble(scaleY.getText()); image.setScale(x, y); canvas.repaint(); } }; scaleX.addActionListener(listener); scaleY.addActionListener(listener); panel.add(new JLabel("Scale-X")); panel.add(scaleX); panel.add(new JLabel("Scale-Y")); panel.add(scaleY); final JTextField ipAddress = new JTextField("www.kickstarter.com"); ipAddress.setColumns(20); final ActionListener ipListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final String destinationIP = ipAddress.getText(); if (StringUtils.isBlank(destinationIP)) { return; } /* * Perform traceroute. */ final List<String> hops; try { if (TracePath.isPathTracingAvailable()) { hops = TracePath.trace(destinationIP); } else { System.err.println("tracepath not available."); if (TracePath.isValidAddress(destinationIP)) { hops = new ArrayList<>(); hops.add(destinationIP); } else { System.err.println(destinationIP + " is no valid IP"); return; } } } catch (Exception ex) { System.err.println("Failed to trace " + destinationIP); ex.printStackTrace(); return; } System.out.println("Trace contains " + hops.size() + " IPs"); /* * Gather locations. */ final List<StringSubject> subjects = new ArrayList<>(); for (String ip : hops) { subjects.add(new StringSubject(ip)); } final List<GeoLocation<StringSubject>> locations; try { long time = -System.currentTimeMillis(); locations = locator.locate(subjects); time += System.currentTimeMillis(); System.out.println("Locating hops for " + destinationIP + " returned " + locations.size() + " valid locations ( time: " + time + " ms)"); System.out.flush(); } catch (Exception e2) { e2.printStackTrace(); return; } /* * Weed-out invalid/unknown locations. */ { GeoLocation<StringSubject> previous = null; for (Iterator<GeoLocation<StringSubject>> it = locations.iterator(); it.hasNext();) { final GeoLocation<StringSubject> location = it.next(); if (!location.hasValidCoordinates() || (previous != null && previous.coordinate().equals(location.coordinate()))) { it.remove(); System.err.println("Ignoring invalid/duplicate location for " + location); } else { previous = location; } } } /* * Populate chart. */ System.out.println("Adding " + locations.size() + " hops to chart"); System.out.flush(); canvas.removeAllCoordinates(); if (locations.size() == 1) { canvas.addCoordinate( PointRenderer.createPoint(locations.get(0), getLabel(locations.get(0)), Color.BLACK)); } else if (locations.size() > 1) { GeoLocation<StringSubject> previous = locations.get(0); MapPoint previousPoint = PointRenderer.createPoint(previous, getLabel(previous), Color.BLACK); final int len = locations.size(); for (int i = 1; i < len; i++) { final GeoLocation<StringSubject> current = locations.get(i); // final MapPoint currentPoint = PointRenderer.createPoint( current , getLabel( current ) , Color.BLACK ); final MapPoint currentPoint = PointRenderer.createPoint(current, Color.BLACK); // canvas.addCoordinate( LineRenderer.createLine( previousPoint , currentPoint , Color.RED ) ); canvas.addCoordinate(CurvedLineRenderer.createLine(previousPoint, currentPoint, Color.RED)); previous = locations.get(i); previousPoint = currentPoint; } } System.out.println("Finished adding"); System.out.flush(); canvas.repaint(); } }; ipAddress.addActionListener(ipListener); panel.add(new JLabel("IP")); panel.add(ipAddress); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(panel, BorderLayout.NORTH); frame.getContentPane().add(canvas, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:ToolBarDemo2.java
protected void addButtons(JToolBar toolBar) { JButton button = null;/*from w ww . j av a 2s . co m*/ //first button button = makeNavigationButton("Back24", PREVIOUS, "Back to previous something-or-other", "Previous"); toolBar.add(button); //second button button = makeNavigationButton("Up24", UP, "Up to something-or-other", "Up"); toolBar.add(button); //third button button = makeNavigationButton("Forward24", NEXT, "Forward to something-or-other", "Next"); toolBar.add(button); //separator toolBar.addSeparator(); //fourth button button = new JButton("Another button"); button.setActionCommand(SOMETHING_ELSE); button.setToolTipText("Something else"); button.addActionListener(this); toolBar.add(button); //fifth component is NOT a button! JTextField textField = new JTextField("A text field"); textField.setColumns(10); textField.addActionListener(this); textField.setActionCommand(TEXT_ENTERED); toolBar.add(textField); }
From source file:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java
public JTextField createJTextField(String content) { Font jtfFont = new Font(Font.SANS_SERIF, Font.PLAIN, 11); JTextField jtf = new JTextField(content); jtf.setColumns(50); jtf.setFont(jtfFont);// w w w. j a va 2s . c o m return jtf; }
From source file:com.game.ui.views.WeaponEditorPanel.java
public void doGui() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JLabel noteLbl = new JLabel( "<html><div style='width : 500px;'>Pls select a value to choose an Weapon or you can create a new " + "Weapon entity below. Once selected a weapon, its' details will be available below</div></html>"); noteLbl.setAlignmentX(0);/* w w w . j a va 2 s. c o m*/ add(noteLbl); DefaultComboBoxModel model = new DefaultComboBoxModel(); for (Item item : GameBean.weaponDetails) { if (item instanceof Weapon) { model.addElement(((Weapon) item).getName()); } } comboBox = new JComboBox(model); comboBox.setSelectedIndex(-1); comboBox.setMaximumSize(new Dimension(100, 30)); comboBox.setAlignmentX(0); comboBox.setActionCommand("dropDown"); comboBox.addActionListener(this); add(Box.createVerticalStrut(10)); add(comboBox); add(Box.createVerticalStrut(10)); JPanel panel1 = new JPanel(); panel1.setAlignmentX(0); panel1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel1.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 weaponDtsLbl = new JLabel("Weapon Details : "); weaponDtsLbl.setFont(new Font("Times New Roman", Font.BOLD, 15)); panel1.add(weaponDtsLbl, c); c.gridwidth = 1; c.gridy = 1; JLabel nameLbl = new JLabel("Name : "); panel1.add(nameLbl, c); c.gridx = 1; JTextField name = new JTextField(""); name.setColumns(20); panel1.add(name, c); c.gridx = 0; c.gridy = 2; JLabel weaponTypeLbl = new JLabel("Weapon Type : "); panel1.add(weaponTypeLbl, c); c.gridx = 1; JComboBox weaponType = new JComboBox(Configuration.weaponTypes); weaponType.setSelectedIndex(0); weaponType.setPreferredSize(name.getPreferredSize()); System.out.println(name.getPreferredSize()); panel1.add(weaponType, c); c.gridx = 0; c.gridy = 3; JLabel attackRangeLbl = new JLabel("Attack Range : "); panel1.add(attackRangeLbl, c); c.gridx = 1; JTextField attackRange = new JTextField(""); attackRange.setColumns(20); panel1.add(attackRange, c); c.gridx = 0; c.gridy = 4; JLabel attackPtsLbl = new JLabel("Attack Points : "); panel1.add(attackPtsLbl, c); c.gridx = 1; JTextField attackPts = new JTextField(""); attackPts.setColumns(20); panel1.add(attackPts, c); c.gridx = 0; c.gridy = 5; c.gridwidth = 2; JButton submit = new JButton("Save"); submit.addActionListener(this); submit.setActionCommand("button"); panel1.add(submit, c); c.gridx = 0; c.gridy = 6; c.gridwidth = 2; c.weighty = 0; c.weightx = 1; validationMess = new JLabel("Pls enter all the fields or pls choose a weapon from the drop down"); validationMess.setForeground(Color.red); validationMess.setVisible(false); panel1.add(validationMess, c); // c.fill = GridBagConstraints.BOTH; // c.gridy = 7; // c.weightx = 1; // c.weighty = 1; // panel1.add(new JLabel(""), c); panel1.setBorder(LineBorder.createGrayLineBorder()); add(panel1); add(Box.createVerticalGlue()); }
From source file:com.game.ui.views.CharachterEditorPanel.java
public void doGui() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JLabel noteLbl = new JLabel("Pls select a value to choose an enemy or you can create a new " + "Enemy entity below. Once selected an Enemy character, its' details will be available below"); noteLbl.setAlignmentX(0);//from ww w . j a v a2 s .c o m // noteLbl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(noteLbl); DefaultComboBoxModel model = new DefaultComboBoxModel(); for (GameCharacter character : GameBean.enemyDetails) { System.out.println(character.getName()); model.addElement(character.getName()); } comboBox = new JComboBox(model); comboBox.setSelectedIndex(-1); comboBox.setMaximumSize(new Dimension(100, 30)); comboBox.setAlignmentX(0); comboBox.setActionCommand("dropDown"); comboBox.addActionListener(this); add(Box.createVerticalStrut(10)); add(comboBox); add(Box.createVerticalStrut(10)); JPanel panel1 = new JPanel(); panel1.setAlignmentX(0); panel1.setBorder(LineBorder.createGrayLineBorder()); panel1.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)); panel1.add(enemyDtlLbl, c); c.gridwidth = 1; c.gridy = 1; JLabel nameLbl = new JLabel("Name : "); panel1.add(nameLbl, c); c.gridx = 1; JTextField name = new JTextField(""); name.setColumns(20); panel1.add(name, c); c.gridx = 0; c.gridy = 2; JLabel imageLbl = new JLabel("Image Path : "); panel1.add(imageLbl, c); c.gridx = 1; JTextField image = new JTextField(""); image.setColumns(20); panel1.add(image, c); c.gridx = 0; c.gridy = 3; JLabel healthLbl = new JLabel("Health Pts : "); panel1.add(healthLbl, c); c.gridx = 1; JTextField health = new JTextField(""); health.setColumns(20); panel1.add(health, c); c.gridx = 0; c.gridy = 4; JLabel attackPtsLbl = new JLabel("Attack Points : "); panel1.add(attackPtsLbl, c); c.gridx = 1; JTextField attackPts = new JTextField(""); attackPts.setColumns(20); panel1.add(attackPts, c); c.gridx = 0; c.gridy = 5; JLabel armoursPtsLbl = new JLabel("Armour Points : "); panel1.add(armoursPtsLbl, c); c.gridx = 1; JTextField armourPts = new JTextField(""); armourPts.setColumns(20); panel1.add(armourPts, c); c.gridx = 0; c.gridy = 6; JLabel attackRngeLbl = new JLabel("Attack Range : "); panel1.add(attackRngeLbl, c); c.gridx = 1; JTextField attackRnge = new JTextField(""); attackRnge.setColumns(20); panel1.add(attackRnge, c); c.gridx = 0; c.gridy = 7; JLabel movementLbl = new JLabel("Movement : "); panel1.add(movementLbl, c); c.gridx = 1; JTextField movement = new JTextField(""); movement.setColumns(20); panel1.add(movement, c); c.gridx = 0; c.gridy = 8; c.gridwidth = 2; JButton submit = new JButton("Save"); submit.addActionListener(this); submit.setActionCommand("button"); panel1.add(submit, c); add(panel1); c.gridx = 0; c.gridy = 9; JLabel validationMess = new JLabel("Pls enter all the fields or pls choose a character from the drop down"); validationMess.setForeground(Color.red); validationMess.setVisible(false); add(validationMess, c); add(Box.createVerticalGlue()); }
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;//w ww . j ava 2 s . com 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:es.emergya.ui.gis.popups.GenericDialog.java
protected void addJoinedRow(String[][] pairs, Integer[] colsLength) { if (pairs == null || pairs.length == 0 || pairs.length != colsLength.length) return;//from w w w . ja v a 2 s .com rows++; int contador = 0; for (int i : colsLength) contador += i; final FlowLayout flowLayout = new FlowLayout(); JPanel panel = new JPanel(flowLayout); panel.setOpaque(false); JTextField jtextField = new JTextField(pairs[0][1]); jtextField.setEditable(true); jtextField.setColumns(colsLength[0]); panel.add(jtextField); mid.add(new JLabel(i18n.getString(pairs[0][0]), JLabel.RIGHT)); for (int i = 1; i < pairs.length; i++) { String[] pair = pairs[i]; if (pair.length != 2) log.error("Par desconocido"); else { panel.add(new JLabel(i18n.getString(pair[0]), JLabel.RIGHT)); jtextField = new JTextField(pair[1]); jtextField.setEditable(true); panel.add(jtextField); jtextField.setColumns(colsLength[i]); } } if (contador < 100) for (int i = contador; i < 100; i += 5) panel.add(new JLabel(" ")); mid.add(panel); for (int i = 2; i < cols; i++) mid.add(Box.createHorizontalGlue()); }
From source file:com.game.ui.views.ItemPanel.java
public void createComponentsForPotion(JPanel panel1, GridBagConstraints c) { c.gridx = 0;//from w w w . ja va 2 s . c o m c.gridy = 2; JLabel potionPts = new JLabel("Potion Pts"); panel1.add(potionPts, c); c.gridx = 1; JTextField potionPtsTxt = new JTextField(""); potionPtsTxt.setColumns(20); panel1.add(potionPtsTxt, c); }
From source file:com.game.ui.views.ItemPanel.java
public void createComponentsForTreasure(JPanel panel1, GridBagConstraints c) { c.gridx = 0;/*from ww w .j a va2 s.co m*/ c.gridy = 2; JLabel treasureVal = new JLabel("Treasure Value"); panel1.add(treasureVal, c); c.gridx = 1; JTextField treasureValTxt = new JTextField(""); treasureValTxt.setColumns(20); panel1.add(treasureValTxt, c); }