List of usage examples for javax.swing Box setMinimumSize
@BeanProperty(description = "The minimum size of the component.") public void setMinimumSize(Dimension minimumSize)
From source file:org.jdal.swing.form.SimpleBoxFormBuilder.java
/** * Builds the panel form.// w w w . j av a 2s . com * @return the form component */ public JComponent getForm() { // set sizes; int columnHeight = 0; for (int h : rowsHeight) columnHeight += h; // add space into components (fillers) columnHeight += (rows - 1) * defaultSpace; for (int i = 0; i < columns.size(); i++) { Box box = columns.get(i); int maxWidth = columnsWidth.get(i) == 0 ? Short.MAX_VALUE : columnsWidth.get(i); box.setMaximumSize(new Dimension(maxWidth, columnHeight)); if (maxWidth < Short.MAX_VALUE && columnHeight < Short.MAX_VALUE) { box.setMinimumSize(new Dimension(maxWidth, columnHeight)); box.setPreferredSize(new Dimension(maxWidth, columnHeight)); } } container.setFocusTraversalPolicy(focusTransversal); container.setFocusTraversalPolicyProvider(true); container.setSize(Short.MAX_VALUE, columnHeight); if (isFixedHeight()) { Dimension maxSize = new Dimension(Short.MAX_VALUE, columnHeight); if (container.isMaximumSizeSet()) { maxSize = container.getMaximumSize(); maxSize.height = columnHeight; } container.setMaximumSize(maxSize); } if (isDebug()) container.setBorder(BorderFactory.createLineBorder(Color.BLUE)); if (border != null) container.setBorder(border); return container; }
From source file:net.sf.firemox.DeckBuilder.java
/** * Creates new form DeckBuilder// w ww . j a v a 2 s .c o m */ private DeckBuilder() { super("DeckBuilder"); form = this; timerPanel = new TimerGlassPane(); cardLoader = new CardLoader(timerPanel); timer = new Timer(200, cardLoader); setGlassPane(timerPanel); try { setIconImage(Picture.loadImage(IdConst.IMAGES_DIR + "deckbuilder.gif")); } catch (Exception e) { // IGNORING } // Load settings loadSettings(); // Initialize components final JMenuItem newItem = UIHelper.buildMenu("menu_db_new", 'n', this); newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK)); final JMenuItem loadItem = UIHelper.buildMenu("menu_db_load", 'o', this); loadItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK)); final JMenuItem saveAsItem = UIHelper.buildMenu("menu_db_saveas", 'a', this); saveAsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0)); final JMenuItem saveItem = UIHelper.buildMenu("menu_db_save", 's', this); saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK)); final JMenuItem quitItem = UIHelper.buildMenu("menu_db_exit", this); quitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_MASK)); final JMenuItem deckConstraintsItem = UIHelper.buildMenu("menu_db_constraints", 'c', this); deckConstraintsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0)); final JMenuItem aboutItem = UIHelper.buildMenu("menu_help_about", 'a', this); aboutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, InputEvent.SHIFT_MASK)); final JMenuItem convertDCK = UIHelper.buildMenu("menu_convert_DCK_MP", this); final JMenu mainMenu = UIHelper.buildMenu("menu_file"); mainMenu.add(newItem); mainMenu.add(loadItem); mainMenu.add(saveAsItem); mainMenu.add(saveItem); mainMenu.add(new JSeparator()); mainMenu.add(quitItem); super.optionMenu = new JMenu("Options"); final JMenu convertMenu = UIHelper.buildMenu("menu_convert"); convertMenu.add(convertDCK); final JMenuItem helpItem = UIHelper.buildMenu("menu_help_help", 'h', this); helpItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); final JMenu helpMenu = new JMenu("?"); helpMenu.add(helpItem); helpMenu.add(deckConstraintsItem); helpMenu.add(aboutItem); final JMenuBar menuBar = new JMenuBar(); menuBar.add(mainMenu); initAbstractMenu(); menuBar.add(optionMenu); menuBar.add(convertMenu); menuBar.add(helpMenu); setJMenuBar(menuBar); addWindowListener(this); // Build the panel containing amount of available cards final JLabel amountLeft = new JLabel("<html>0/?", SwingConstants.RIGHT); // Build the left list allListModel = new MListModel<MCardCompare>(amountLeft, false); leftList = new ThreadSafeJList(allListModel); leftList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); leftList.setLayoutOrientation(JList.VERTICAL); leftList.getSelectionModel().addListSelectionListener(this); leftList.addMouseListener(this); leftList.setVisibleRowCount(10); // Initialize the text field containing the amount to add addQtyTxt = new JTextField("1"); // Build the "Add" button addButton = new JButton(LanguageManager.getString("db_add")); addButton.setMnemonic('a'); addButton.setEnabled(false); // Build the panel containing : "Add" amount and "Add" button final Box addPanel = Box.createHorizontalBox(); addPanel.add(addButton); addPanel.add(addQtyTxt); addPanel.setMaximumSize(new Dimension(32010, 26)); // Build the panel containing the selected card name cardNameTxt = new JTextField(); new HireListener(cardNameTxt, addButton, this, leftList); final JLabel searchLabel = new JLabel(LanguageManager.getString("db_search") + " : "); searchLabel.setLabelFor(cardNameTxt); // Build the panel containing search label and card name text field final Box searchPanel = Box.createHorizontalBox(); searchPanel.add(searchLabel); searchPanel.add(cardNameTxt); searchPanel.setMaximumSize(new Dimension(32010, 26)); listScrollerLeft = new JScrollPane(leftList); MToolKit.addOverlay(listScrollerLeft); // Build the left panel containing : list, available amount, "Add" panel final JPanel srcPanel = new JPanel(null); srcPanel.add(searchPanel); srcPanel.add(listScrollerLeft); srcPanel.add(amountLeft); srcPanel.add(addPanel); srcPanel.setMinimumSize(new Dimension(220, 200)); srcPanel.setLayout(new BoxLayout(srcPanel, BoxLayout.Y_AXIS)); // Initialize constraints constraintsChecker = new ConstraintsChecker(); constraintsChecker.setBorder(new EtchedBorder()); final JScrollPane constraintsCheckerScroll = new JScrollPane(constraintsChecker); MToolKit.addOverlay(constraintsCheckerScroll); // create a pane with the oracle text for the present card oracleText = new JLabel(); oracleText.setPreferredSize(new Dimension(180, 200)); oracleText.setVerticalAlignment(SwingConstants.TOP); final JScrollPane oracle = new JScrollPane(oracleText, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); MToolKit.addOverlay(oracle); // build some Pie Charts and a panel to display it initSets(); datasets = new ChartSets(); final JTabbedPane tabbedPane = new JTabbedPane(); for (ChartFilter filter : ChartFilter.values()) { final Dataset dataSet = filter.createDataSet(this); final JFreeChart chart = new JFreeChart(null, null, filter.createPlot(dataSet, painterMapper.get(filter)), false); datasets.addDataSet(filter, dataSet); ChartPanel pieChartPanel = new ChartPanel(chart, true); tabbedPane.add(pieChartPanel, filter.getTitle()); } // add the Constraints scroll panel and Oracle text Pane to the tabbedPane tabbedPane.add(constraintsCheckerScroll, LanguageManager.getString("db_constraints")); tabbedPane.add(oracle, LanguageManager.getString("db_text")); tabbedPane.setSelectedComponent(oracle); // The toollBar for color filtering toolBar = new JToolBar(); toolBar.setFloatable(false); final JButton clearButton = UIHelper.buildButton("clear"); clearButton.addActionListener(this); toolBar.add(clearButton); final JToggleButton toggleColorlessButton = new JToggleButton( UIHelper.getTbsIcon("mana/colorless/small/" + MdbLoader.unknownSmlMana), true); toggleColorlessButton.setActionCommand("0"); toggleColorlessButton.addActionListener(this); toolBar.add(toggleColorlessButton); for (int index = 1; index < IdCardColors.CARD_COLOR_NAMES.length; index++) { final JToggleButton toggleButton = new JToggleButton( UIHelper.getTbsIcon("mana/colored/small/" + MdbLoader.coloredSmlManas[index]), true); toggleButton.setActionCommand(String.valueOf(index)); toggleButton.addActionListener(this); toolBar.add(toggleButton); } // sorted card type combobox creation final List<String> idCards = new ArrayList<String>(Arrays.asList(CardFactory.exportedIdCardNames)); Collections.sort(idCards); final Object[] cardTypes = ArrayUtils.addAll(new String[] { LanguageManager.getString("db_types.any") }, idCards.toArray()); idCardComboBox = new JComboBox(cardTypes); idCardComboBox.setSelectedIndex(0); idCardComboBox.addActionListener(this); idCardComboBox.setActionCommand("cardTypeFilter"); // sorted card properties combobox creation final List<String> properties = new ArrayList<String>( CardFactory.getPropertiesName(DeckConstraints.getMinProperty(), DeckConstraints.getMaxProperty())); Collections.sort(properties); final Object[] cardProperties = ArrayUtils .addAll(new String[] { LanguageManager.getString("db_properties.any") }, properties.toArray()); propertiesComboBox = new JComboBox(cardProperties); propertiesComboBox.setSelectedIndex(0); propertiesComboBox.addActionListener(this); propertiesComboBox.setActionCommand("propertyFilter"); final JLabel colors = new JLabel(" " + LanguageManager.getString("colors") + " : "); final JLabel types = new JLabel(" " + LanguageManager.getString("types") + " : "); final JLabel property = new JLabel(" " + LanguageManager.getString("properties") + " : "); // filter Panel with colors toolBar and card type combobox final Box filterPanel = Box.createHorizontalBox(); filterPanel.add(colors); filterPanel.add(toolBar); filterPanel.add(types); filterPanel.add(idCardComboBox); filterPanel.add(property); filterPanel.add(propertiesComboBox); getContentPane().add(filterPanel, BorderLayout.NORTH); // Destination section : // Build the panel containing amount of available cards final JLabel rightAmount = new JLabel("0/?", SwingConstants.RIGHT); rightAmount.setMaximumSize(new Dimension(220, 26)); // Build the right list rightListModel = new MCardTableModel(new MListModel<MCardCompare>(rightAmount, true)); rightListModel.addTableModelListener(this); rightList = new JTable(rightListModel); rightList.setShowGrid(false); rightList.setTableHeader(null); rightList.getSelectionModel().addListSelectionListener(this); rightList.getColumnModel().getColumn(0).setMaxWidth(25); rightList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); // Build the panel containing the selected deck deckNameTxt = new JTextField("loading..."); deckNameTxt.setEditable(false); deckNameTxt.setBorder(null); final JLabel deckLabel = new JLabel(LanguageManager.getString("db_deck") + " : "); deckLabel.setLabelFor(deckNameTxt); final Box deckNamePanel = Box.createHorizontalBox(); deckNamePanel.add(deckLabel); deckNamePanel.add(deckNameTxt); deckNamePanel.setMaximumSize(new Dimension(220, 26)); // Initialize the text field containing the amount to remove removeQtyTxt = new JTextField("1"); // Build the "Remove" button removeButton = new JButton(LanguageManager.getString("db_remove")); removeButton.setMnemonic('r'); removeButton.addMouseListener(this); removeButton.setEnabled(false); // Build the panel containing : "Remove" amount and "Remove" button final Box removePanel = Box.createHorizontalBox(); removePanel.add(removeButton); removePanel.add(removeQtyTxt); removePanel.setMaximumSize(new Dimension(220, 26)); // Build the right panel containing : list, available amount, constraints final JScrollPane deskListScroller = new JScrollPane(rightList); MToolKit.addOverlay(deskListScroller); deskListScroller.setBorder(BorderFactory.createLineBorder(Color.GRAY)); deskListScroller.setMinimumSize(new Dimension(220, 200)); deskListScroller.setMaximumSize(new Dimension(220, 32000)); final Box destPanel = Box.createVerticalBox(); destPanel.add(deckNamePanel); destPanel.add(deskListScroller); destPanel.add(rightAmount); destPanel.add(removePanel); destPanel.setMinimumSize(new Dimension(220, 200)); destPanel.setMaximumSize(new Dimension(220, 32000)); // Build the panel containing the name of card in picture cardPictureNameTxt = new JLabel("<html><i>no selected card</i>"); final Box cardPictureNamePanel = Box.createHorizontalBox(); cardPictureNamePanel.add(cardPictureNameTxt); cardPictureNamePanel.setMaximumSize(new Dimension(32010, 26)); // Group the detail panels final JPanel viewCard = new JPanel(null); viewCard.add(cardPictureNamePanel); viewCard.add(CardView.getInstance()); viewCard.add(tabbedPane); viewCard.setLayout(new BoxLayout(viewCard, BoxLayout.Y_AXIS)); final Box mainPanel = Box.createHorizontalBox(); mainPanel.add(destPanel); mainPanel.add(viewCard); // Add the main panel getContentPane().add(srcPanel, BorderLayout.WEST); getContentPane().add(mainPanel, BorderLayout.CENTER); // Size this frame getRootPane().setPreferredSize(new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT)); getRootPane().setMinimumSize(getRootPane().getPreferredSize()); pack(); }