Created
May 28, 2015 17:32
-
-
Save mverzilli/679f0e4bc9a7ba6a5f9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package simurrythmia.ui.util; | |
import java.awt.GridBagConstraints; | |
import java.awt.GridBagLayout; | |
import java.awt.Insets; | |
import javax.swing.BorderFactory; | |
import javax.swing.JComponent; | |
import javax.swing.JPanel; | |
public class LayoutUtils { | |
public static JPanel createPanel(String title) { | |
JPanel panel = createPanel(); | |
panel.setBorder(BorderFactory.createTitledBorder(title)); | |
return panel; | |
} | |
public static JPanel createPanel() { | |
JPanel panel = new JPanel(); | |
panel.setLayout(new GridBagLayout()); | |
return panel; | |
} | |
public static GridBagConstraints layoutControls(JPanel panel, JComponent[][] controlMatrix){ | |
GridBagConstraints c = new GridBagConstraints(); | |
c.insets = new Insets(5, 10, 5, 10); | |
c.fill = GridBagConstraints.BOTH; | |
for (int row = 0; row < controlMatrix.length; row++){ | |
for (int col = 0; col < controlMatrix[row].length; col++){ | |
c.gridx = col; | |
c.gridy = row; | |
panel.add(controlMatrix[row][col], c); | |
} | |
} | |
return c; | |
} | |
public static JPanel padding(){ | |
return new JPanel(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Main panel es un contenedor, controlMatrix es una matriz de | |
//componentes de Swing que se van a entrar en un table layout | |
//de acuerdo a la matriz. | |
//LayoutUtils.padding() es para poner "aire" en alguna de las celdas de la matriz :P | |
JComponent[][] controlMatrix = new JComponent[][] { | |
new JComponent[] { constant, periodLabel, period, msLabel }, | |
new JComponent[] { variable, addReferenceValue }, | |
new JComponent[] { LayoutUtils.padding(), scrollPane } | |
}; | |
LayoutUtils.layoutControls(mainPanel, controlMatrix); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment