private void calculateGridSize() { int scrollPaneWidth = scrollPane.getWidth(); int scrollPaneHeight = scrollPane.getHeight(); int items = components.size(); int columns = scrollPaneWidth / width - 1; int rows = scrollPaneHeight / height; if(columns<1) { columns =1; } gridPane.removeAll(); for (int i = 0; i < components.size(); i++) { gridPane.add(components.get(i)); } if (items < (rows * columns)) { for (int i = 0; i < (rows * columns - items); i++) { gridPane.add(new Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0))); } } gridPane.setLayout(new java.awt.GridLayout(-1, columns)); }
/** * Creates a new instance. * * @param icon the icon to show on the left of the bar * @param titleKey the key to the title to show on the bar, retrieved from the {@link MessageBundle} */ public TaskTitleBar(FontAwesomeGlyph icon, String titleKey) { /* The basics. */ super(); /* The icon. */ this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); this.add(new GlyphIcon(icon)); /* The title. */ JLabel title = new JLabel(MessageBundle.get(titleKey)); title.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, FILLER_MARGIN)); this.add(title); /* An opaque filler (1px height -> horizontal line). */ Filler filler = new Filler(new Dimension(0, FILLER_HEIGHT), new Dimension(0, FILLER_HEIGHT), new Dimension(Short.MAX_VALUE, FILLER_HEIGHT)); filler.setBackground(Color.BLACK); filler.setOpaque(true); this.add(filler); /* An "add" button. */ GlyphButton addButton = new GlyphButton(FontAwesomeGlyph.PLUS); addButton.setBorder(BorderFactory.createEmptyBorder(0, FILLER_MARGIN, 0, 0)); this.add(addButton); }
public String getPrecedingLabel() { Container container = component.getParent(); if (container == null) { return null; } List<Component> allComponents = findAllComponents(); // Find labels in the same row (LTR) // In the same row: labelx < componentx, labely >= componenty Point locComponent = component.getLocationOnScreen(); List<Component> rowLeft = new ArrayList<Component>(); for (Component label : allComponents) { Point locLabel = label.getLocationOnScreen(); if (!(label instanceof JPanel) && locLabel.getX() < locComponent.getX() && locLabel.getY() >= locComponent.getY() && locLabel.getY() <= locComponent.getY() + component.getHeight() && !(label instanceof Filler)) { rowLeft.add(label); } } Collections.sort(rowLeft, new Comparator<Component>() { @Override public int compare(Component o1, Component o2) { Point locO1 = o1.getLocationOnScreen(); Point locO2 = o2.getLocationOnScreen(); return (int) (locO1.getX() - locO2.getX()); } }); if (rowLeft.size() > 0 && rowLeft.get(rowLeft.size() - 1) instanceof JLabel) { return stripLastColon(((JLabel) rowLeft.get(rowLeft.size() - 1)).getText().trim()); } return null; }
private void initFiller() { Filler filler = new Filler(new Dimension(0, 0), new Dimension(0, 0), new Dimension(32767, 32767)); filler.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent me) { mainFrame.getGlassPane().setVisible(false); } }); add(filler, BorderLayout.CENTER); }
private Filler getLeftFiller() { Filler filler = new Filler( new Dimension(0, 0), new Dimension(0, 0), new Dimension(32767, 32767)); filler.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { mainFrame.getGlassPane().setVisible(false); } }); return filler; }
protected Filler getAnotherObject() { return null; // TODO: could not update property // return new Filler( // new Dimension(9, 8), // new Dimension(7, 6), // new Dimension(5, 4)); }
IconlessLabel() { setLayout(new BorderLayout()); setOpaque(true); label.setOpaque(true); add(label,BorderLayout.CENTER); Dimension dim = new Dimension(1, 24); box = new Filler(dim, dim, dim); box.setOpaque(true); add(box,BorderLayout.EAST); }
private void buildGui() { // create components JPanel mainP = new JPanel(new BorderLayout(0, 20)); Box butP = Box.createHorizontalBox(); okB = new JButton(_okAction); cancelB = new JButton(_cancelAction); _mainPanel = createMainPanel(); //layout components if(_isCreating) { _stayOpenCB = new JCheckBox("Don't close this dialog"); _stayOpenCB.setSelected(false); butP.add(_stayOpenCB); butP.add(new Filler(new Dimension(0,0), new Dimension(30,0), new Dimension(Short.MAX_VALUE, 0)) ); } else { butP.add(Box.createHorizontalGlue()); } butP.add(okB); butP.add(Box.createHorizontalStrut(10)); butP.add(cancelB); mainP.add(butP, BorderLayout.SOUTH); getContentPane().add(mainP); mainP.add(_mainPanel, BorderLayout.CENTER); mainP.setBorder(BorderFactory.createEmptyBorder(20,20,20,20)); this.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) {dispose();} }); setDefaultActions(getRootPane()); }
protected Filler getObject() { return new Filler( new Dimension(1, 2), new Dimension(3, 4), new Dimension(5, 6)); }