package org.leumasjaffe.recipe.view; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.JLabel; import javax.swing.JPanel; import org.leumasjaffe.recipe.model.Duration; @SuppressWarnings("serial") public class DurationPanel extends JPanel { private JLabel lblTime; public DurationPanel(String name) { GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[]{0, 0, 0}; gridBagLayout.rowHeights = new int[]{0, 0}; gridBagLayout.columnWeights = new double[]{0.0, 0.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE}; setLayout(gridBagLayout); JLabel lblName = new JLabel(name + ": "); GridBagConstraints gbc_lblName = new GridBagConstraints(); gbc_lblName.insets = new Insets(0, 0, 0, 5); gbc_lblName.gridx = 0; gbc_lblName.gridy = 0; add(lblName, gbc_lblName); lblTime = new JLabel(); GridBagConstraints gbc_lblTime = new GridBagConstraints(); gbc_lblTime.gridx = 1; gbc_lblTime.gridy = 0; add(lblTime, gbc_lblTime); } public DurationPanel(String name, Duration duration) { this(name); setModel(duration); } public void setModel(final Duration duration) { lblTime.setText(duration.toString()); } }