List of usage examples for javax.swing BorderFactory createEmptyBorder
public static Border createEmptyBorder(int top, int left, int bottom, int right)
From source file:RadioButtonDemo.java
public RadioButtonDemo() { super(new BorderLayout()); //Create the radio buttons. JRadioButton birdButton = new JRadioButton(birdString); birdButton.setMnemonic(KeyEvent.VK_B); birdButton.setActionCommand(birdString); birdButton.setSelected(true);// w w w . ja v a2 s. c o m JRadioButton catButton = new JRadioButton(catString); catButton.setMnemonic(KeyEvent.VK_C); catButton.setActionCommand(catString); JRadioButton dogButton = new JRadioButton(dogString); dogButton.setMnemonic(KeyEvent.VK_D); dogButton.setActionCommand(dogString); JRadioButton rabbitButton = new JRadioButton(rabbitString); rabbitButton.setMnemonic(KeyEvent.VK_R); rabbitButton.setActionCommand(rabbitString); JRadioButton pigButton = new JRadioButton(pigString); pigButton.setMnemonic(KeyEvent.VK_P); pigButton.setActionCommand(pigString); //Group the radio buttons. ButtonGroup group = new ButtonGroup(); group.add(birdButton); group.add(catButton); group.add(dogButton); group.add(rabbitButton); group.add(pigButton); //Register a listener for the radio buttons. birdButton.addActionListener(this); catButton.addActionListener(this); dogButton.addActionListener(this); rabbitButton.addActionListener(this); pigButton.addActionListener(this); //Set up the picture label. picture = new JLabel(createImageIcon("images/" + birdString + ".gif")); //The preferred size is hard-coded to be the width of the //widest image and the height of the tallest image. //A real program would compute this. picture.setPreferredSize(new Dimension(177, 122)); //Put the radio buttons in a column in a panel. JPanel radioPanel = new JPanel(new GridLayout(0, 1)); radioPanel.add(birdButton); radioPanel.add(catButton); radioPanel.add(dogButton); radioPanel.add(rabbitButton); radioPanel.add(pigButton); add(radioPanel, BorderLayout.LINE_START); add(picture, BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:components.SpinnerDemo3.java
public SpinnerDemo3(boolean cycleMonths) { super(new SpringLayout()); String[] labels = { "Month: ", "Year: ", "Another Date: " }; int numPairs = labels.length; calendar = Calendar.getInstance(); JFormattedTextField ftf = null; //Add the first label-spinner pair. String[] monthStrings = getMonthStrings(); //get month names SpinnerListModel monthModel = null; if (cycleMonths) { //use custom model monthModel = new CyclingSpinnerListModel(monthStrings); } else { //use standard model monthModel = new SpinnerListModel(monthStrings); }/*from w w w .j ava2s . co m*/ JSpinner spinner = addLabeledSpinner(this, labels[0], monthModel); //Tweak the spinner's formatted text field. ftf = getTextField(spinner); if (ftf != null) { ftf.setColumns(8); //specify more width than we need ftf.setHorizontalAlignment(JTextField.RIGHT); } //Add second label-spinner pair. int currentYear = calendar.get(Calendar.YEAR); SpinnerModel yearModel = new SpinnerNumberModel(currentYear, //initial value currentYear - 100, //min currentYear + 100, //max 1); //step //If we're cycling, hook this model up to the month model. if (monthModel instanceof CyclingSpinnerListModel) { ((CyclingSpinnerListModel) monthModel).setLinkedModel(yearModel); } spinner = addLabeledSpinner(this, labels[1], yearModel); //Make the year be formatted without a thousands separator. spinner.setEditor(new JSpinner.NumberEditor(spinner, "#")); //Add the third label-spinner pair. Date initDate = calendar.getTime(); calendar.add(Calendar.YEAR, -100); Date earliestDate = calendar.getTime(); calendar.add(Calendar.YEAR, 200); Date latestDate = calendar.getTime(); SpinnerDateModel dateModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.YEAR);//ignored for user input dateSpinner = spinner = addLabeledSpinner(this, labels[2], dateModel); spinner.setEditor(new JSpinner.DateEditor(spinner, "MM/yyyy")); //Tweak the spinner's formatted text field. ftf = getTextField(spinner); if (ftf != null) { ftf.setHorizontalAlignment(JTextField.RIGHT); ftf.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 3)); } spinner.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); //XXX: No easy way to get to the buttons and change their border. setSeasonalColor(dateModel.getDate()); //initialize color //Listen for changes on the date spinner. dateSpinner.addChangeListener(this); //Lay out the panel. SpringUtilities.makeCompactGrid(this, numPairs, 2, //rows, cols 10, 10, //initX, initY 6, 10); //xPad, yPad }
From source file:net.sf.xmm.moviemanager.gui.DialogIMDB.java
JPanel createMoviehitsList() { /* Movies List panel...*/ JPanel panelMoviesList = new JPanel(); panelMoviesList.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), Localizer.get("DialogIMDB.panel-movie-list.title")), //$NON-NLS-1$ BorderFactory.createEmptyBorder(5, 5, 5, 5))); listMovies = new JList() { public String getToolTipText(MouseEvent e) { if (getCellBounds(0, 0) == null) return null; String retVal = null; int row = (int) e.getPoint().getY() / (int) getCellBounds(0, 0).getHeight(); if (row >= 0 && row < getModel().getSize() && getMoviesList().getModel().getElementAt(row) instanceof ModelIMDbSearchHit) { retVal = ((ModelIMDbSearchHit) getMoviesList().getModel().getElementAt(row)).getAka(); if (retVal != null && retVal.trim().equals("")) //$NON-NLS-1$ retVal = null;//from w w w . j av a 2 s .c o m } return retVal; } public JToolTip createToolTip() { JMultiLineToolTip tooltip = new JMultiLineToolTip(); tooltip.setComponent(this); return tooltip; } }; // Unfortunately setting tooltip timeout affects ALL tooltips ToolTipManager ttm = ToolTipManager.sharedInstance(); ttm.registerComponent(listMovies); ttm.setInitialDelay(0); ttm.setReshowDelay(0); listMovies.setFixedCellHeight(18); listMovies.setFont(new Font(listMovies.getFont().getName(), Font.PLAIN, listMovies.getFont().getSize())); listMovies.setLayoutOrientation(JList.VERTICAL); listMovies.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listMovies.setCellRenderer(new MovieHitListCellRenderer()); listMovies.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent event) { // Open we page if (SwingUtilities.isRightMouseButton(event)) { int index = listMovies.locationToIndex(event.getPoint()); if (index >= 0) { ModelIMDbSearchHit hit = (ModelIMDbSearchHit) listMovies.getModel().getElementAt(index); if (hit.getUrlID() != null && !hit.getUrlID().equals("")) { BrowserOpener opener = new BrowserOpener(hit.getCompleteUrl()); opener.executeOpenBrowser(MovieManager.getConfig().getSystemWebBrowser(), MovieManager.getConfig().getBrowserPath()); } } } else if (SwingUtilities.isLeftMouseButton(event) && event.getClickCount() >= 2) { buttonSelect.doClick(); } } }); KeyStroke enterKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true); ActionListener listKeyBoardActionListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { log.debug("ActionPerformed: " + "Movielist - ENTER pressed."); //$NON-NLS-1$ buttonSelect.doClick(); } }; listMovies.registerKeyboardAction(listKeyBoardActionListener, enterKeyStroke, JComponent.WHEN_FOCUSED); JScrollPane scrollPaneMovies = new JScrollPane(listMovies); scrollPaneMovies.setAutoscrolls(true); //scrollPaneMovies.registerKeyboardAction(listKeyBoardActionListener,enterKeyStroke, JComponent.WHEN_FOCUSED); panelMoviesList.setLayout(new BorderLayout()); panelMoviesList.add(scrollPaneMovies, BorderLayout.CENTER); return panelMoviesList; }
From source file:com.game.ui.views.CharacterEditor.java
/** * This method draws up the gui on the panel. *///ww w.j a va 2 s .c o m public void doGui() { JPanel outerPane = new JPanel(); outerPane.setLayout(new GridBagLayout()); // setLayout(new GridBagLayout()); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JLabel noteLbl = new JLabel(lblContent); noteLbl.setAlignmentX(0); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.NONE; c.insets = new Insets(5, 5, 5, 5); c.gridwidth = 4; c.gridy = 0; c.gridx = 0; outerPane.add(noteLbl, c); System.out.println(c.gridy); c.gridy++; System.out.println(c.gridy); c.gridx = 0; c.gridwidth = 1; comboBox = new JComboBox(model); comboBox.setSelectedIndex(-1); comboBox.setMaximumSize(new Dimension(100, 30)); comboBox.setAlignmentX(0); comboBox.setActionCommand("dropDown"); comboBox.addActionListener(this); outerPane.add(comboBox, c); c.gridy++; JLabel nameLbl = new JLabel("Name : "); outerPane.add(nameLbl, c); c.gridx++; name = new JTextField(); name.setColumns(20); outerPane.add(name, c); c.gridx = 0; c.gridy++; JLabel imageLbl = new JLabel("Image Path : "); outerPane.add(imageLbl, c); c.gridx++; imgPath = new JTextField(); imgPath.setColumns(20); outerPane.add(imgPath, c); c.gridx = 0; c.gridy++; JLabel hitPtsLbl = new JLabel("Hit Points : "); outerPane.add(hitPtsLbl, c); c.gridx++; hitPoints = new JTextField(); hitPoints.setColumns(20); outerPane.add(hitPoints, c); c.gridx = 0; c.gridy++; JLabel lvl = new JLabel("Level : "); outerPane.add(lvl, c); c.gridx++; level = new JTextField(); level.setColumns(20); /*if(!isEnemy){ level.setText("1"); level.setEnabled(false); }*/ outerPane.add(level, c); c.gridx = 0; c.gridy++; JLabel mlWpn = new JLabel("Melee Weapon : "); outerPane.add(mlWpn, c); c.gridx++; model = new DefaultComboBoxModel(); LinkedList<String> meleeWpnList = new LinkedList<String>(); LinkedList<String> rngdWpnList = new LinkedList<String>(); for (Item item : GameBean.weaponDetails) { Weapon wpn = (Weapon) item; if (wpn.getWeaponType().equalsIgnoreCase(Configuration.weaponTypes[0])) { meleeWpnList.add(wpn.getName()); } else { rngdWpnList.add(wpn.getName()); } weaponMap.put(wpn.getName(), wpn); } meleeWeapon = new JComboBox(new DefaultComboBoxModel(meleeWpnList.toArray())); meleeWeapon.setSelectedIndex(-1); meleeWeapon.setMaximumSize(new Dimension(100, 30)); outerPane.add(meleeWeapon, c); c.gridx++; JLabel rngdWpn = new JLabel("Ranged Weapon : "); outerPane.add(rngdWpn, c); c.gridx++; rangedWeapon = new JComboBox(new DefaultComboBoxModel(rngdWpnList.toArray())); rangedWeapon.setSelectedIndex(-1); rangedWeapon.setMaximumSize(new Dimension(100, 30)); outerPane.add(rangedWeapon, c); c.gridy++; c.gridx = 0; JLabel armourLbl = new JLabel("Armour : "); outerPane.add(armourLbl, c); c.gridx++; LinkedList<String> armourList = new LinkedList<String>(); LinkedList<String> shildList = new LinkedList<String>(); for (Item item : GameBean.armourDetails) { Armour temp = (Armour) item; if (temp.getArmourType() != null) { if (temp.getArmourType().equalsIgnoreCase(Configuration.armourTypes[1])) { armourList.add(temp.getName()); } else { shildList.add(temp.getName()); } } else { armourList.add(temp.getName()); // else if(temp.getArmourType().equalsIgnoreCase(Configuration.armourTypes[2])) shildList.add(temp.getName()); } armorMap.put(temp.getName(), temp); } armour = new JComboBox(new DefaultComboBoxModel(armourList.toArray())); armour.setSelectedIndex(-1); armour.setMaximumSize(new Dimension(100, 30)); outerPane.add(armour, c); c.gridx++; JLabel shieldLbl = new JLabel("Shield : "); outerPane.add(shieldLbl, c); c.gridx++; shield = new JComboBox(new DefaultComboBoxModel(shildList.toArray())); shield.setSelectedIndex(-1); shield.setMaximumSize(new Dimension(100, 30)); outerPane.add(shield, c); ta = new JTextArea(10, 50); ta.setRows(40); ta.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY)); JScrollPane scrollPane = new JScrollPane(ta); scrollPane.setPreferredSize(new Dimension(600, 250)); c.gridx = 0; c.gridy++; c.fill = GridBagConstraints.BOTH; c.gridwidth = 4; c.gridheight = 4; c.weightx = .5; c.weighty = 1; outerPane.add(scrollPane, c); c.gridy += 4; c.gridx = 0; c.weightx = 0; c.weighty = 0; c.fill = GridBagConstraints.NONE; c.gridheight = 1; c.gridwidth = 1; JButton generate = new JButton("Generate"); JButton submit = new JButton("Submit"); outerPane.add(generate, c); submit.addActionListener(this); generate.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { ta.setText(""); HashSet<Integer> set = new HashSet<Integer>(); int strength = getUniqueVal(set); int constitution = getUniqueVal(set); int dext = getUniqueVal(set); int intel = getUniqueVal(set); int charisma = getUniqueVal(set); int wisdom = getUniqueVal(set); if (character == null) { builder = new CharacterBuilder(isEnemy); } else { builder = new CharacterBuilder(character); } builder.setStrength(strength); builder.setConstitution(constitution); builder.setDexterity(dext); builder.setIntelligence(intel); builder.setCharisma(charisma); builder.setWisdom(wisdom); int strModifier = GameUtils.calculateAbilityModifier(strength); int conModifier = GameUtils.calculateAbilityModifier(constitution); int dexModifier = GameUtils.calculateAbilityModifier(dext); int wisModifier = GameUtils.calculateAbilityModifier(wisdom); int intModifier = GameUtils.calculateAbilityModifier(intel); int chaModifier = GameUtils.calculateAbilityModifier(charisma); builder.setStrengthModifier(strModifier); builder.setConstitutionModifier(conModifier); builder.setCharismaModifier(chaModifier); builder.setWisdomModifier(wisModifier); builder.setIntelligenceModifier(intModifier); builder.setDexterityModifier(dexModifier); String type = null; if (constitution < strength && constitution > dext) { type = "Bully"; builder.setType("Bully"); } else if (dext > constitution && constitution > strength) { builder.setType("Nimble"); type = "Nimble"; } else { builder.setType("Tank"); type = "Tank"; } ta.append("Strength : " + strength); ta.append("\nDexterity : " + dexModifier); ta.append("\nConstitution : " + constitution); ta.append("\nIntelligence : " + intel); ta.append("\nCharisma: " + charisma); ta.append("\nWisdom : " + wisdom); ta.append("\nType :" + type); ta.append("\nStrength Modifier :" + strModifier); ta.append("\nConstitution Modifier :" + conModifier); ta.append("\nDexterity Modifier :" + dexModifier); generated = true; if (character != null) { character = builder.build(); } } }); c.gridx++; outerPane.add(submit, c); validationMess = new JLabel(); validationMess.setForeground(Color.red); // validationMess.setVisible(false); c.gridy++; c.gridx = 0; c.gridwidth = 4; outerPane.add(validationMess, c); JScrollPane outerScrollPane = new JScrollPane(outerPane); setLayout(new BorderLayout()); add(outerScrollPane, BorderLayout.CENTER); }
From source file:levelBuilder.DialogMaker.java
/** * First window to interact with. Offers options of load graph or new graph. *///w w w .j av a 2 s . c om private static void splashWindow() { final JFrame frame = new JFrame("Dialog Maker"); //Handles button pushes. class SplashActionHandler implements ActionListener { @Override public void actionPerformed(ActionEvent e) { frame.dispose(); if (e.getActionCommand().equals("loadGraph")) loadFilePopup(); else loadGraph(true); } } //Loads and sets background image. BufferedImage img = null; try { img = ImageIO.read(new File(imgDir + "splash.png")); } catch (IOException e) { e.printStackTrace(); } final BufferedImage img2 = img; JPanel panel = new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(img2, 0, 0, null); } }; panel.setOpaque(true); panel.setLayout(new BorderLayout()); panel.setPreferredSize(new Dimension(800, 600)); panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 300, 0)); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); buttonPanel.setOpaque(false); //Buttons JButton loadMap = new JButton("Load Graph"); loadMap.setActionCommand("loadGraph"); loadMap.addActionListener(new SplashActionHandler()); buttonPanel.add(loadMap); JButton newMap = new JButton("New Graph"); newMap.setActionCommand("newGraph"); newMap.addActionListener(new SplashActionHandler()); buttonPanel.add(newMap); panel.add(buttonPanel, BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:com.sshtools.sshterm.SshTermCommandTab.java
/** * Creates a new SshToolsConnectionCommandTab object. *//*from www . j a v a2 s. c om*/ public SshTermCommandTab() { super(); JPanel main = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.NORTH; gbc.insets = new Insets(0, 2, 2, 2); Insets ins2 = new Insets(2, 24, 2, 2); gbc.weightx = 1.0; requestPseudoTerminal.getModel().setSelected(false); disconnectOnSessionClose.getModel().setSelected(true); UIUtil.jGridBagAdd(main, requestPseudoTerminal, gbc, GridBagConstraints.REMAINDER); UIUtil.jGridBagAdd(main, disconnectOnSessionClose, gbc, GridBagConstraints.REMAINDER); UIUtil.jGridBagAdd(main, new JSeparator(JSeparator.HORIZONTAL), gbc, GridBagConstraints.REMAINDER); UIUtil.jGridBagAdd(main, onceAuthenticated, gbc, GridBagConstraints.REMAINDER); group.add(doNothing); group.add(startShell); group.add(executeCommands); startShell.setSelected(true); UIUtil.jGridBagAdd(main, doNothing, gbc, GridBagConstraints.REMAINDER); UIUtil.jGridBagAdd(main, startShell, gbc, GridBagConstraints.REMAINDER); UIUtil.jGridBagAdd(main, executeCommands, gbc, GridBagConstraints.REMAINDER); gbc.fill = GridBagConstraints.BOTH; gbc.insets = ins2; gbc.weighty = 1.0; //commands.setLineWrap(true); commands.setBorder(BorderFactory.createEtchedBorder()); JScrollPane scroll = new JScrollPane(commands); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); UIUtil.jGridBagAdd(main, scroll, gbc, GridBagConstraints.REMAINDER); IconWrapperPanel iconProxyDetailsPanel = new IconWrapperPanel(new ResourceIcon(COMMANDS_ICON), main); commands.setRows(8); // This panel setLayout(new BorderLayout()); setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.NORTH; gbc.insets = new Insets(2, 2, 2, 2); gbc.weightx = 1.0; add(iconProxyDetailsPanel, BorderLayout.NORTH); }
From source file:com.igormaznitsa.sciareto.ui.MainFrame.java
public MainFrame(@Nonnull @MustNotContainNull final String... args) { super();//from w w w . ja v a2s . c o m initComponents(); this.stackPanel = new JPanel(); this.stackPanel.setFocusable(false); this.stackPanel.setOpaque(false); this.stackPanel.setBorder(BorderFactory.createEmptyBorder(32, 32, 16, 32)); this.stackPanel.setLayout(new BoxLayout(this.stackPanel, BoxLayout.Y_AXIS)); final JPanel glassPanel = (JPanel) this.getGlassPane(); glassPanel.setOpaque(false); this.setGlassPane(glassPanel); glassPanel.setLayout(new BorderLayout(8, 8)); glassPanel.add(Box.createGlue(), BorderLayout.CENTER); final JPanel ppanel = new JPanel(new BorderLayout(0, 0)); ppanel.setFocusable(false); ppanel.setOpaque(false); ppanel.setCursor(null); ppanel.add(this.stackPanel, BorderLayout.SOUTH); glassPanel.add(ppanel, BorderLayout.EAST); this.stackPanel.add(Box.createGlue()); glassPanel.setVisible(false); this.setTitle("Scia Reto"); setIconImage(UiUtils.loadImage("logo256x256.png")); this.stateless = args.length > 0; final MainFrame theInstance = this; this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(@Nonnull final WindowEvent e) { if (doClosing()) { dispose(); } } }); this.tabPane = new EditorTabPane(this); this.explorerTree = new ExplorerTree(this); final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); splitPane.setOneTouchExpandable(true); splitPane.setDividerLocation(250); splitPane.setResizeWeight(0.0d); splitPane.setLeftComponent(this.explorerTree); splitPane.setRightComponent(this.tabPane); add(splitPane, BorderLayout.CENTER); this.menuOpenRecentProject.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { final File[] lastOpenedProjects = FileHistoryManager.getInstance().getLastOpenedProjects(); if (lastOpenedProjects.length > 0) { for (final File folder : lastOpenedProjects) { final JMenuItem item = new JMenuItem(folder.getName()); item.setToolTipText(folder.getAbsolutePath()); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openProject(folder, false); } }); menuOpenRecentProject.add(item); } } } @Override public void menuDeselected(MenuEvent e) { menuOpenRecentProject.removeAll(); } @Override public void menuCanceled(MenuEvent e) { } }); this.menuOpenRecentFile.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { final File[] lastOpenedFiles = FileHistoryManager.getInstance().getLastOpenedFiles(); if (lastOpenedFiles.length > 0) { for (final File file : lastOpenedFiles) { final JMenuItem item = new JMenuItem(file.getName()); item.setToolTipText(file.getAbsolutePath()); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openFileAsTab(file); } }); menuOpenRecentFile.add(item); } } } @Override public void menuDeselected(MenuEvent e) { menuOpenRecentFile.removeAll(); } @Override public void menuCanceled(MenuEvent e) { } }); if (!this.stateless) { restoreState(); } else { boolean openedProject = false; for (final String filePath : args) { final File file = new File(filePath); if (file.isDirectory()) { openedProject = true; openProject(file, true); } else if (file.isFile()) { openFileAsTab(file); } } if (!openedProject) { //TODO try to hide project panel! } } final LookAndFeel current = UIManager.getLookAndFeel(); final ButtonGroup lfGroup = new ButtonGroup(); final String currentLFClassName = current.getClass().getName(); for (final UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(info.getName()); lfGroup.add(menuItem); if (currentLFClassName.equals(info.getClassName())) { menuItem.setSelected(true); } menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(@Nonnull final ActionEvent e) { try { UIManager.setLookAndFeel(info.getClassName()); SwingUtilities.updateComponentTreeUI(theInstance); PreferencesManager.getInstance().getPreferences().put(Main.PROPERTY_LOOKANDFEEL, info.getClassName()); PreferencesManager.getInstance().flush(); } catch (Exception ex) { LOGGER.error("Can't change LF", ex); } } }); this.menuLookAndFeel.add(menuItem); } }
From source file:marytts.tools.voiceimport.DatabaseImportMain.java
protected void setupGUI() { // A scroll pane containing one labelled checkbox per component, // and a "run selected components" button below. GridBagLayout gridBagLayout = new GridBagLayout(); GridBagConstraints gridC = new GridBagConstraints(); getContentPane().setLayout(gridBagLayout); JPanel checkboxPane = new JPanel(); checkboxPane.setLayout(new BoxLayout(checkboxPane, BoxLayout.Y_AXIS)); //checkboxPane.setPreferredSize(new Dimension(300, 300)); int compIndex = 0; for (int j = 0; j < groups2Comps.length; j++) { String[] nextGroup = groups2Comps[j]; JPanel groupPane = new JPanel(); groupPane.setLayout(new BoxLayout(groupPane, BoxLayout.Y_AXIS)); groupPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(nextGroup[0]), BorderFactory.createEmptyBorder(1, 1, 1, 1))); for (int i = 1; i < nextGroup.length; i++) { JButton configButton = new JButton(); Icon configIcon = new ImageIcon(DatabaseImportMain.class.getResource("configure.png"), "Configure"); configButton.setIcon(configIcon); configButton.setPreferredSize(new Dimension(configIcon.getIconWidth(), configIcon.getIconHeight())); configButton.addActionListener(new ConfigButtonActionListener(nextGroup[i])); configButton.setBorderPainted(false); //System.out.println("Adding checkbox for "+components[i].getClass().getName()); checkboxes[compIndex] = new JCheckBox(nextGroup[i]); checkboxes[compIndex].setFocusable(true); //checkboxes[i].setPreferredSize(new Dimension(200, 30)); JPanel line = new JPanel(); line.setLayout(new BorderLayout(5, 0)); line.add(configButton, BorderLayout.WEST); line.add(checkboxes[compIndex], BorderLayout.CENTER); groupPane.add(line);/*w w w .ja va 2s. c om*/ compIndex++; } checkboxPane.add(groupPane); } gridC.gridx = 0; gridC.gridy = 0; gridC.fill = GridBagConstraints.BOTH; JScrollPane scrollPane = new JScrollPane(checkboxPane); scrollPane.setPreferredSize(new Dimension(450, 300)); gridBagLayout.setConstraints(scrollPane, gridC); getContentPane().add(scrollPane); JButton helpButton = new JButton("Help"); helpButton.setMnemonic(KeyEvent.VK_H); helpButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { displayHelpGUI(); } }); JButton settingsButton = new JButton("Settings"); settingsButton.setMnemonic(KeyEvent.VK_S); settingsButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { currentComponent = "Global properties"; displaySettingsGUI(); } }); runButton = new JButton("Run"); runButton.setMnemonic(KeyEvent.VK_R); runButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { runSelectedComponents(); } }); JButton quitAndSaveButton = new JButton("Quit"); quitAndSaveButton.setMnemonic(KeyEvent.VK_Q); quitAndSaveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { askIfSave(); } catch (IOException ioe) { ioe.printStackTrace(); } System.exit(0); } }); gridC.gridy = 1; JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout()); //buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.X_AXIS)); //runButton.setAlignmentX(JButton.LEFT_ALIGNMENT); buttonPanel.add(runButton); //helpButton.setAlignmentX(JButton.LEFT_ALIGNMENT); buttonPanel.add(helpButton); //settingsButton.setAlignmentX(JButton.LEFT_ALIGNMENT); buttonPanel.add(settingsButton); //buttonPanel.add(Box.createHorizontalGlue()); //quitAndSaveButton.setAlignmentX(JButton.RIGHT_ALIGNMENT); buttonPanel.add(quitAndSaveButton); gridBagLayout.setConstraints(buttonPanel, gridC); getContentPane().add(buttonPanel); //getContentPane().setPreferredSize(new Dimension(300, 300)); // End program when closing window: addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { try { askIfSave(); } catch (IOException ioe) { ioe.printStackTrace(); } System.exit(0); } }); }
From source file:FormatterFactoryDemo.java
public FormatterFactoryDemo() { super(new BorderLayout()); setUpFormats();/*from w ww.j a v a 2 s .c o m*/ double payment = computePayment(amount, rate, numPeriods); // Create the labels. amountLabel = new JLabel(amountString); rateLabel = new JLabel(rateString); numPeriodsLabel = new JLabel(numPeriodsString); paymentLabel = new JLabel(paymentString); // Create the text fields and set them up. amountField = new JFormattedTextField(new DefaultFormatterFactory(new NumberFormatter(amountDisplayFormat), new NumberFormatter(amountDisplayFormat), new NumberFormatter(amountEditFormat))); amountField.setValue(new Double(amount)); amountField.setColumns(10); amountField.addPropertyChangeListener("value", this); NumberFormatter percentEditFormatter = new NumberFormatter(percentEditFormat) { public String valueToString(Object o) throws ParseException { Number number = (Number) o; if (number != null) { double d = number.doubleValue() * 100.0; number = new Double(d); } return super.valueToString(number); } public Object stringToValue(String s) throws ParseException { Number number = (Number) super.stringToValue(s); if (number != null) { double d = number.doubleValue() / 100.0; number = new Double(d); } return number; } }; rateField = new JFormattedTextField(new DefaultFormatterFactory(new NumberFormatter(percentDisplayFormat), new NumberFormatter(percentDisplayFormat), percentEditFormatter)); rateField.setValue(new Double(rate)); rateField.setColumns(10); rateField.addPropertyChangeListener("value", this); numPeriodsField = new JFormattedTextField(); numPeriodsField.setValue(new Integer(numPeriods)); numPeriodsField.setColumns(10); numPeriodsField.addPropertyChangeListener("value", this); paymentField = new JFormattedTextField(paymentFormat); paymentField.setValue(new Double(payment)); paymentField.setColumns(10); paymentField.setEditable(false); paymentField.setForeground(Color.red); // Tell accessibility tools about label/textfield pairs. amountLabel.setLabelFor(amountField); rateLabel.setLabelFor(rateField); numPeriodsLabel.setLabelFor(numPeriodsField); paymentLabel.setLabelFor(paymentField); // Lay out the labels in a panel. JPanel labelPane = new JPanel(new GridLayout(0, 1)); labelPane.add(amountLabel); labelPane.add(rateLabel); labelPane.add(numPeriodsLabel); labelPane.add(paymentLabel); // Layout the text fields in a panel. JPanel fieldPane = new JPanel(new GridLayout(0, 1)); fieldPane.add(amountField); fieldPane.add(rateField); fieldPane.add(numPeriodsField); fieldPane.add(paymentField); // Put the panels in this panel, labels on left, // text fields on right. setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); add(labelPane, BorderLayout.CENTER); add(fieldPane, BorderLayout.LINE_END); }
From source file:ch.zhaw.simulation.diagram.charteditor.DefaultTitleEditor.java
/** * Standard constructor: builds a panel for displaying/editing the * properties of the specified title.//from w ww. j a v a 2 s . c o m * * @param title * the title, which should be changed. */ public DefaultTitleEditor(Title title) { if (title == null) { this.showTitle = false; this.titleFont = SimulationDiagramTheme.DEFAULT_TITLE_FONT; this.titleField = new JTextField(); this.titlePaint = new PaintSample(Color.BLACK); } else { TextTitle t = (TextTitle) title; this.showTitle = title.isVisible(); this.titleFont = t.getFont(); this.titleField = new JTextField(t.getText()); this.titlePaint = new PaintSample(t.getPaint()); } System.out.println(this.titleFont.getName()); setLayout(new BorderLayout()); JPanel general = new JPanel(new BorderLayout()); general.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), localizationResources.getString("General"))); JPanel interior = new JPanel(new LCBLayout(4)); interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); interior.add(new JLabel(localizationResources.getString("Show_Title"))); this.showTitleCheckBox = new JCheckBox(); this.showTitleCheckBox.setSelected(this.showTitle); this.showTitleCheckBox.setActionCommand("ShowTitle"); this.showTitleCheckBox.addActionListener(this); interior.add(new JPanel()); interior.add(this.showTitleCheckBox); JLabel titleLabel = new JLabel(localizationResources.getString("Text")); interior.add(titleLabel); interior.add(this.titleField); interior.add(new JPanel()); JLabel fontLabel = new JLabel(localizationResources.getString("Font")); this.fontfield = new FontDisplayField(this.titleFont); this.selectFontButton = new JButton(localizationResources.getString("Select...")); this.selectFontButton.setActionCommand("SelectFont"); this.selectFontButton.addActionListener(this); interior.add(fontLabel); interior.add(this.fontfield); interior.add(this.selectFontButton); JLabel colorLabel = new JLabel(localizationResources.getString("Color")); this.selectPaintButton = new JButton(localizationResources.getString("Select...")); this.selectPaintButton.setActionCommand("SelectPaint"); this.selectPaintButton.addActionListener(this); interior.add(colorLabel); interior.add(this.titlePaint); interior.add(this.selectPaintButton); this.enableOrDisableControls(); general.add(interior); add(general, BorderLayout.NORTH); }