Java Code Examples for javax.swing.JPanel#doLayout()

The following examples show how to use javax.swing.JPanel#doLayout() . These examples are extracted from open source projects. 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
/**
 * Returns button with resource amounts and given text. If resources is empty then returns button
 * with just the text.
 */
public JButton getResourcesButton(final ResourceCollection resources, final String text) {
  if (resources.isEmpty()) {
    return new JButton(text);
  }
  final JPanel panel = getResourcesPanel(resources);
  panel.setOpaque(false);
  panel.add(new JLabel(text));
  panel.setSize(panel.getPreferredSize());
  panel.doLayout();
  final BufferedImage image =
      new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_ARGB);
  final Graphics2D g = image.createGraphics();
  panel.paint(g);
  g.dispose();
  return new JButton(new ImageIcon(image));
}
 
Example 2
Source Project: jace   File: UserInterface.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static Component createRowEditor(Row r) {
    JPanel rowEditor = new JPanel();
    rowEditor.setSize(800, 24);
    rowEditor.setLayout(new BoxLayout(rowEditor, BoxLayout.X_AXIS));
    rowEditor.setBackground(Theme.background.color);
    rowEditor.setOpaque(true);
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.A1.tone", 3, toneListner));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.A1.volume", 1));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.A1.commands", 3));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.B1.tone", 3, toneListner));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.B1.volume", 1));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.B1.commands", 3));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.C1.tone", 3, toneListner));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.C1.volume", 1));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.C1.commands", 3));
    rowEditor.add(EditableLabel.generateTextLabel(r, "ay1noisePeriod", 4));
    rowEditor.add(EditableLabel.generateTextLabel(r, "ay1envelopePeriod", 4));
    rowEditor.add(generateEnvelopeEditor(r.ay1envelopeShape, r, "ay2envelopeShape"));

    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.A2.tone", 3, toneListner));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.A2.volume", 1));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.A2.commands", 3));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.B2.tone", 3, toneListner));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.B2.volume", 1));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.B2.commands", 3));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.C2.tone", 3, toneListner));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.C2.volume", 1));
    rowEditor.add(EditableLabel.generateTextLabel(r, "channels.C2.commands", 3));
    rowEditor.add(EditableLabel.generateTextLabel(r, "ay2noisePeriod", 4));
    rowEditor.add(EditableLabel.generateTextLabel(r, "ay2envelopePeriod", 4));
    rowEditor.add(generateEnvelopeEditor(r.ay2envelopeShape, r, "ay2envelopeShape"));

    rowEditor.add(EditableLabel.generateTextLabel(r, "globalCommands", 6));
    rowEditor.doLayout();
    return rowEditor;
}