javax.swing.Spring Java Examples

The following examples show how to use javax.swing.Spring. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Working.java    From sheepit-client with GNU General Public License v2.0 5 votes vote down vote up
private Spring getBestWidth(Container parent, int rows, int cols) {
	Spring x = Spring.constant(0);
	Spring width = Spring.constant(0);
	for (int c = 0; c < cols; c++) {
		
		for (int r = 0; r < rows; r++) {
			width = Spring.max(width, getConstraintsForCell(r, c, parent, cols).getWidth());
		}
	}
	return width;
}
 
Example #2
Source File: SummaryPanel.java    From swift-k with Apache License 2.0 4 votes vote down vote up
private void makeProgressBars(SpringLayout l) {
    JComponent prevLabel = null, prevBar = null;
    bars = new JProgressBar[SummaryItem.STATES.length];
    
    SpringLayout ls = new SpringLayout();
    JPanel appSummary = new JPanel();
    appSummary.setBorder(BorderFactory.createTitledBorder(
        BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "App Summary"));
    add(appSummary);
    l.putConstraint(SpringLayout.WEST, appSummary, 5, SpringLayout.WEST, this);
    l.putConstraint(SpringLayout.EAST, appSummary, -5, SpringLayout.EAST, this);
    l.putConstraint(SpringLayout.NORTH, appSummary, 25, SpringLayout.NORTH, this);
    
    appSummary.setLayout(ls);
    
    
    for (int i = 0; i < SummaryItem.STATES.length; i++) {
        JLabel label = new JLabel(SummaryItem.STATES[i] + ":");
        appSummary.add(label);
        
        JProgressBar lb = new JProgressBar();
        bars[i] = lb;
        lb.setString("0");
        lb.setStringPainted(true);
        appSummary.add(lb);
    
        fixEdges(ls, label, lb, appSummary);
        if (prevLabel == null) {
            ls.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, appSummary);
        }
        else {
            ls.putConstraint(SpringLayout.NORTH, label, 10, SpringLayout.SOUTH, prevLabel);
        }
        prevLabel = label;
        prevBar = lb;
    }
    
    JLabel hl = new JLabel("Heap:");
    memory = makeProgress(l, hl);
    
    l.putConstraint(SpringLayout.SOUTH, appSummary, -25, SpringLayout.NORTH, hl);
    l.putConstraint(SpringLayout.SOUTH, hl, -25, SpringLayout.SOUTH, this);
    
    Spring maxW = Spring.constant(0);
    
    for (int i = 0; i < SummaryItem.STATES.length; i++) {
        maxW = Spring.max(maxW, ls.getConstraints(appSummary.getComponent(i * 2)).getWidth());
    }
    
    for (int i = 0; i < SummaryItem.STATES.length; i++) {
        SpringLayout.Constraints c = ls.getConstraints(appSummary.getComponent(i * 2));
        c.setWidth(maxW);
    }
}