public ComboBoxDemo2() { setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); String[] patternExamples = { "dd MMMMM yyyy", "dd.MM.yy", "MM/dd/yy", "yyyy.MM.dd G 'at' hh:mm:ss z", "EEE, MMM d, ''yy", "h:mm a", "H:mm:ss:SSS", "K:mm a,z", "yyyy.MMMMM.dd GGG hh:mm aaa" }; currentPattern = patternExamples[0]; // Set up the UI for selecting a pattern. JLabel patternLabel1 = new JLabel("Enter the pattern string or"); JLabel patternLabel2 = new JLabel("select one from the list:"); JComboBox patternList = new JComboBox(patternExamples); patternList.setEditable(true); patternList.addActionListener(this); // Create the UI for displaying result. JLabel resultLabel = new JLabel("Current Date/Time", JLabel.LEADING); // == LEFT result = new JLabel(" "); result.setForeground(Color.black); result.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(Color.black), BorderFactory.createEmptyBorder(5, 5, 5, 5))); // Lay out everything. JPanel patternPanel = new JPanel(); patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.PAGE_AXIS)); patternPanel.add(patternLabel1); patternPanel.add(patternLabel2); patternList.setAlignmentX(Component.LEFT_ALIGNMENT); patternPanel.add(patternList); JPanel resultPanel = new JPanel(new GridLayout(0, 1)); resultPanel.add(resultLabel); resultPanel.add(result); patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT); resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT); add(patternPanel); add(Box.createRigidArea(new Dimension(0, 10))); add(resultPanel); setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); reformat(); } // constructor
/** OptionPaneDemo Constructor */ public OptionPaneDemo(SwingSet2 swingset) { // Set the title for this demo, and an icon used to represent this // demo inside the SwingSet2 app. super(swingset, "OptionPaneDemo", "toolbar/JOptionPane.gif"); JPanel demo = getDemoPanel(); demo.setLayout(new BoxLayout(demo, BoxLayout.X_AXIS)); JPanel bp = new JPanel() { public Dimension getMaximumSize() { return new Dimension(getPreferredSize().width, super.getMaximumSize().height); } }; bp.setLayout(new BoxLayout(bp, BoxLayout.Y_AXIS)); bp.add(Box.createRigidArea(VGAP30)); bp.add(Box.createRigidArea(VGAP30)); bp.add(createInputDialogButton()); bp.add(Box.createRigidArea(VGAP15)); bp.add(createWarningDialogButton()); bp.add(Box.createRigidArea(VGAP15)); bp.add(createMessageDialogButton()); bp.add(Box.createRigidArea(VGAP15)); bp.add(createComponentDialogButton()); bp.add(Box.createRigidArea(VGAP15)); bp.add(createConfirmDialogButton()); bp.add(Box.createVerticalGlue()); demo.add(Box.createHorizontalGlue()); demo.add(bp); demo.add(Box.createHorizontalGlue()); }
public void createFileChooserDemo() { theImage = new JLabel(""); jpgIcon = createImageIcon("filechooser/jpgIcon.jpg", "jpg image"); gifIcon = createImageIcon("filechooser/gifIcon.gif", "gif image"); JPanel demoPanel = getDemoPanel(); demoPanel.setLayout(new BoxLayout(demoPanel, BoxLayout.Y_AXIS)); JPanel innerPanel = new JPanel(); innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.X_AXIS)); demoPanel.add(Box.createRigidArea(VGAP20)); demoPanel.add(innerPanel); demoPanel.add(Box.createRigidArea(VGAP20)); innerPanel.add(Box.createRigidArea(HGAP20)); // Create a panel to hold buttons JPanel buttonPanel = new JPanel() { public Dimension getMaximumSize() { return new Dimension(getPreferredSize().width, super.getMaximumSize().height); } }; buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS)); buttonPanel.add(Box.createRigidArea(VGAP15)); buttonPanel.add(createPlainFileChooserButton()); buttonPanel.add(Box.createRigidArea(VGAP15)); buttonPanel.add(createPreviewFileChooserButton()); buttonPanel.add(Box.createRigidArea(VGAP15)); buttonPanel.add(createCustomFileChooserButton()); buttonPanel.add(Box.createVerticalGlue()); // Create a panel to hold the image JPanel imagePanel = new JPanel(); imagePanel.setLayout(new BorderLayout()); imagePanel.setBorder(new BevelBorder(BevelBorder.LOWERED)); JScrollPane scroller = new JScrollPane(theImage); scroller.getVerticalScrollBar().setUnitIncrement(10); scroller.getHorizontalScrollBar().setUnitIncrement(10); imagePanel.add(scroller, BorderLayout.CENTER); // add buttons and image panels to inner panel innerPanel.add(buttonPanel); innerPanel.add(Box.createRigidArea(HGAP30)); innerPanel.add(imagePanel); innerPanel.add(Box.createRigidArea(HGAP20)); }
public PlayerView(String player) { playerName = new String(player); // Set-Up Top of Score Area namePanel = new JPanel(); nameText = new JLabel(player); nameText.setFont(ScoreFont); namePanel.setLayout(new BorderLayout()); namePanel.add(nameText, BorderLayout.CENTER); scorePanel = new JPanel(); scoreText = new JLabel(" 0"); scoreText.setFont(ScoreFont); scorePanel.setLayout(new BorderLayout()); scorePanel.add(scoreText, BorderLayout.CENTER); topPanel = new JPanel(); BoxLayout layout = new BoxLayout(topPanel, BoxLayout.LINE_AXIS); topPanel.setLayout(layout); topPanel.add(namePanel); topPanel.add(Box.createRigidArea(new Dimension(10, 0))); topPanel.add(scorePanel); topPanel.add(Box.createRigidArea(new Dimension(10, 0))); // // topPanel.setLayout( new BorderLayout()); // topPanel.add(namePanel, BorderLayout.WEST); // topPanel.add(scorePanel, BorderLayout.EAST); // // Create bordering for top panel Border raisedBevel, loweredBevel, compound; raisedBevel = BorderFactory.createRaisedBevelBorder(); loweredBevel = BorderFactory.createLoweredBevelBorder(); compound = BorderFactory.createCompoundBorder(raisedBevel, loweredBevel); topPanel.setBorder(compound); // Set-Up area to display word list wordPanel = new JPanel(); Border etched = BorderFactory.createEtchedBorder(); TitledBorder etchedTitle = BorderFactory.createTitledBorder(etched, "Word List"); etchedTitle.setTitleJustification(TitledBorder.RIGHT); wordPanel.setBorder(etchedTitle); myWordList = new ExpandableList(); myWordList.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String word = e.getActionCommand(); java.util.List<BoardCell> list = myFinder.cellsForWord(myBoard, word); myBoardPanel.highlightDice(list); } }); wordPanel.add( new JScrollPane( myWordList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); setLayout(new BorderLayout(30, 30)); add(topPanel, BorderLayout.NORTH); add(wordPanel, BorderLayout.CENTER); }