下面列出了javax.swing.JComponent#setMinimumSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private <X, Y> JScrollPane makeList2(
Algebra<catdata.aql.exp.Ty, catdata.aql.exp.En, catdata.aql.exp.Sym, catdata.aql.exp.Fk, catdata.aql.exp.Att, catdata.aql.exp.Gen, catdata.aql.exp.Sk, X, Y> algebra,
boolean b, int l) {
List<JComponent> list = makeList(algebra, b, l);
JPanel c = new JPanel();
c.setLayout(new BoxLayout(c, BoxLayout.PAGE_AXIS));
for (JComponent x : list) {
x.setAlignmentX(Component.LEFT_ALIGNMENT);
x.setMinimumSize(x.getPreferredSize());
c.add(x);
}
JPanel p = new JPanel(new GridLayout(1, 1));
p.add(c);
JScrollPane jsp = new JScrollPane(p);
c.setBorder(BorderFactory.createEmptyBorder());
p.setBorder(BorderFactory.createEmptyBorder());
jsp.setBorder(BorderFactory.createEmptyBorder());
return jsp;
}
private <e, L> void apgInst0(JTabbedPane pane, ApgInstance<L, e> G) {
List<JComponent> list = new LinkedList<>();
Object[][] rowData;
Object[] colNames;
rowData = new Object[G.Es.size()][3];
colNames = new Object[3];
colNames[0] = "Element";
colNames[1] = "Label";
colNames[2] = "Value";
int j = 0;
for (Entry<e, Pair<L, ApgTerm<L, e>>> lt : G.Es.entrySet()) {
rowData[j][0] = lt.getKey();
rowData[j][1] = lt.getValue().first;
rowData[j][2] = lt.getValue().second;
j++;
}
list.add(GuiUtil.makeTable(BorderFactory.createEmptyBorder(), "Data", rowData, colNames));
JPanel c = new JPanel();
c.setLayout(new BoxLayout(c, BoxLayout.PAGE_AXIS));
for (JComponent x : list) {
x.setAlignmentX(Component.LEFT_ALIGNMENT);
x.setMinimumSize(x.getPreferredSize());
c.add(x);
}
JPanel p = new JPanel(new GridLayout(1, 1));
p.add(c);
JScrollPane jsp = new JScrollPane(p);
c.setBorder(BorderFactory.createEmptyBorder());
p.setBorder(BorderFactory.createEmptyBorder());
jsp.setBorder(BorderFactory.createEmptyBorder());
pane.addTab("Tables", p);
}
private <L> void apgSch0(JTabbedPane pane, ApgSchema<L> Ls) {
List<JComponent> list = new LinkedList<>();
Object[][] rowData = new Object[Ls.size()][2];
Object[] colNames = new Object[2];
colNames[0] = "Label";
colNames[1] = "Type";
int j = 0;
for (Entry<L, ApgTy<L>> lt : Ls.entrySet()) {
rowData[j][0] = lt.getKey();
rowData[j][1] = lt.getValue();
j++;
}
list.add(GuiUtil.makeTable(BorderFactory.createEmptyBorder(), "Schema", rowData, colNames));
JPanel c = new JPanel();
c.setLayout(new BoxLayout(c, BoxLayout.PAGE_AXIS));
for (JComponent x : list) {
x.setAlignmentX(Component.LEFT_ALIGNMENT);
x.setMinimumSize(x.getPreferredSize());
c.add(x);
}
JPanel p = new JPanel(new GridLayout(1, 1));
p.add(c);
JScrollPane jsp = new JScrollPane(p);
c.setBorder(BorderFactory.createEmptyBorder());
p.setBorder(BorderFactory.createEmptyBorder());
jsp.setBorder(BorderFactory.createEmptyBorder());
pane.addTab("Tables", p);
}
public static JComponent makeGrid(List<JComponent> list) {
JPanel ret = new JPanel();
ret.setLayout(new BoxLayout(ret, BoxLayout.PAGE_AXIS));
// int i = 0;
for (JComponent x : list) {
x.setAlignmentX(Component.LEFT_ALIGNMENT);
x.setMinimumSize(x.getPreferredSize());
ret.add(x);
// ret.add(Box.)
// ret.add(Box.createHorizontalGlue());
}
// ret.add(new JLabel(""), Box.cre);
JPanel p = new JPanel(new GridLayout(1, 1));
p.add(ret);
JScrollPane jsp = new JScrollPane(p);// , JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
// JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
ret.setBorder(BorderFactory.createEmptyBorder());
p.setBorder(BorderFactory.createEmptyBorder());
// jsp.setBorder(BorderFactory.createEmptyBorder());
return jsp;
}
public FGSatelliteUndockedProvider(FunctionGraphPlugin plugin, FGController controller,
JComponent satelliteComponent) {
super(plugin.getTool(), NAME, plugin.getName());
this.controller = controller;
this.satelliteComponent = satelliteComponent;
satelliteComponent.setMinimumSize(new Dimension(400, 400));
setHelpLocation(new HelpLocation("FunctionGraphPlugin", "Satellite_View_Dock"));
setIcon(ICON);
setDefaultWindowPosition(WindowPosition.WINDOW);
setWindowMenuGroup(FunctionGraphPlugin.FUNCTION_GRAPH_NAME);
addToTool();
}
public JComponent createComponent() {
JComponent jc = new JComponent() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
TextBlock.this.paint((Graphics2D) g);
}
};
jc.setOpaque(false);
jc.setMinimumSize(new Dimension(getWidth(), getHeight()));
jc.setPreferredSize(new Dimension(getWidth(), getHeight()));
return jc;
}
/**
* Add a component for the Text.
*
* @param panel Container.
* @param constraints Constraints.
* @param textPane Text pane.
* @param undo Button undo.
*/
protected void addTextContents(
JPanel panel, GridBagConstraints constraints,
MWPane textPane, JButton undo) {
if (textPane != null) {
Configuration config = Configuration.getConfiguration();
textPane.setBackground(Color.WHITE);
textPane.setEditable(true);
if (undo != null) {
textPane.getUndoManager().setUndoLevels(config.getInt(
null,
ConfigurationValueInteger.ANALYSIS_UNDO_LVL));
}
textPane.addPropertyChangeListener(
MWPane.PROPERTY_MODIFIED,
new PropertyChangeListener() {
/* (non-Javadoc)
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
*/
@Override
public void propertyChange(@SuppressWarnings("unused") PropertyChangeEvent evt) {
updateComponentState();
}
});
JComponent scrollContents = MWPane.createComplexPane(textPane);
scrollContents.setMinimumSize(new Dimension(100, 100));
scrollContents.setPreferredSize(new Dimension(1000, 500));
panel.add(scrollContents, constraints);
}
}
private JComponent setPrefSize (JComponent comp, int minPrefW, int minPrefH)
{
if (comp == null)
return null ;
comp.setMinimumSize(new Dimension(200, 150));
comp.setPreferredSize(new Dimension(minPrefW, minPrefH));
comp.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
return comp ;
}
private JComponent setPrefSize (JComponent comp, int minPrefW, int minPrefH)
{
if (comp == null)
return null ;
comp.setMinimumSize(new Dimension(100, 100));
comp.setPreferredSize(new Dimension(minPrefW, minPrefH));
comp.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
return comp ;
}
private JComponent setMinPrefMaxWidth (JComponent comp, int minPrefW, int maxW, int prefHeight)
{
if (comp == null)
return null ;
comp.setMinimumSize(new Dimension(minPrefW, 0));
comp.setPreferredSize(new Dimension(minPrefW, prefHeight));
comp.setMaximumSize(new Dimension(maxW, Integer.MAX_VALUE));
return comp ;
}
private JComponent setMinPrefMaxWidth (JComponent comp, int minPrefW, int maxW)
{
if (comp == null)
return null ;
comp.setMinimumSize(new Dimension(minPrefW, 0));
comp.setPreferredSize(new Dimension(minPrefW, 25));
comp.setMaximumSize(new Dimension(maxW, Integer.MAX_VALUE));
return comp ;
}
public static void setSize(JComponent component, Dimension dimension) {
component.setMinimumSize(dimension);
component.setPreferredSize(dimension);
}
private void createSubmitParamPanel() {
// Main panel which holds all the components in a grid
pnSubmitParam = new GridBagPanel();
pnSideMenu.add(pnSubmitParam, BorderLayout.NORTH);
int rowCounter = 0;
// Create labels and components for each parameter
for (Parameter p : paramSubmit.getParameters()) {
if (!(p instanceof UserParameter))
continue;
UserParameter up = (UserParameter) p;
JComponent comp = up.createEditingComponent();
comp.setToolTipText(up.getDescription());
// Set the initial value
Object value = up.getValue();
if (value != null)
up.setValueToComponent(comp, value);
// By calling this we make sure the components will never be resized
// smaller than their optimal size
comp.setMinimumSize(comp.getPreferredSize());
comp.setToolTipText(up.getDescription());
// add separator
if (p.getName().equals(LibrarySubmitParameters.LOCALFILE.getName())) {
pnSubmitParam.addSeparator(0, rowCounter, 2);
rowCounter++;
}
JLabel label = new JLabel(p.getName());
pnSubmitParam.add(label, 0, rowCounter);
label.setLabelFor(comp);
parametersAndComponents.put(p.getName(), comp);
JComboBox t = new JComboBox();
int comboh = t.getPreferredSize().height;
int comph = comp.getPreferredSize().height;
int verticalWeight = comph > 2 * comboh ? 1 : 0;
pnSubmitParam.add(comp, 1, rowCounter, 1, 1, 1, verticalWeight, GridBagConstraints.VERTICAL);
rowCounter++;
}
}
private void createMetaDataPanel() {
// Main panel which holds all the components in a grid
pnMetaData = new GridBagPanel();
scrollMeta = new JScrollPane(pnMetaData);
scrollMeta.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollMeta.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
pnSideMenu.add(scrollMeta, BorderLayout.CENTER);
int rowCounter = 0;
int vertWeightSum = 0;
// Create labels and components for each parameter
for (Parameter p : paramMeta.getParameters()) {
if (!(p instanceof UserParameter))
continue;
UserParameter up = (UserParameter) p;
JComponent comp = up.createEditingComponent();
comp.setToolTipText(up.getDescription());
// Set the initial value
Object value = up.getValue();
if (value != null)
up.setValueToComponent(comp, value);
// By calling this we make sure the components will never be resized
// smaller than their optimal size
comp.setMinimumSize(comp.getPreferredSize());
comp.setToolTipText(up.getDescription());
JLabel label = new JLabel(p.getName());
pnMetaData.add(label, 0, rowCounter);
label.setLabelFor(comp);
parametersAndComponents.put(p.getName(), comp);
JComboBox t = new JComboBox();
int comboh = t.getPreferredSize().height;
int comph = comp.getPreferredSize().height;
// Multiple selection will be expandable, other components not
int verticalWeight = comph > 2 * comboh ? 1 : 0;
vertWeightSum += verticalWeight;
pnMetaData.add(comp, 1, rowCounter, 1, 1, 1, verticalWeight, GridBagConstraints.VERTICAL);
rowCounter++;
}
}
private void setJComponentSize(Dimension comboBoxDimension, JComponent comboBox) {
comboBox.setPreferredSize(comboBoxDimension);
comboBox.setMinimumSize(comboBoxDimension);
}