Example usage for java.awt Container Container

List of usage examples for java.awt Container Container

Introduction

In this page you can find the example usage for java.awt Container Container.

Prototype

public Container() 

Source Link

Document

Constructs a new Container.

Usage

From source file:Main.java

/**
 * Create a component buffer of width w and height h
 * //  w  w  w  . j  a v a  2  s  .  c  o  m
 * @param width
 * @param height
 * @return
 */
public static Component createBufferPanel(int width, int height) {
    Container buffer = new Container();
    buffer.setMinimumSize(new Dimension(width, height));
    buffer.setPreferredSize(new Dimension(width, height));
    buffer.setMaximumSize(new Dimension(width, height));

    return buffer;
}

From source file:Main.java

Main() {
    JFrame f1 = new JFrame("Selection");
    Container f = new Container();
    f.setLayout(new FlowLayout());

    String s[] = { "Red", "Green", "Yellow", "Black" };
    c = new JComboBox(s);
    JPanel p = new JPanel();

    c.addItemListener(this);

    f1.add(p);//from   ww w . j a v  a  2  s .c  o  m
    p.add(c);
    f1.setSize(500, 500);
    f1.setVisible(true);
}

From source file:SquareLayout.java

/**
 * Creates a new Container with SquareLayout which will contain the specified
 * component.//from   ww w.j av a  2  s  .  c om
 */

public static Container createSquareContainer(Component child) {
    Container container = new Container();
    container.setLayout(new SquareLayout());
    container.add(child);

    return container;
}

From source file:PictureBall.java

public PictureBall() {

    // Create the universe
    SimpleUniverse universe = new SimpleUniverse();

    // Create a structure to contain objects
    BranchGroup group = new BranchGroup();

    // Set up colors
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f red = new Color3f(0.7f, .15f, .15f);

    // Set up the texture map
    TextureLoader loader = new TextureLoader("K:\\3d\\Arizona.jpg", "LUMINANCE", new Container());
    Texture texture = loader.getTexture();
    texture.setBoundaryModeS(Texture.WRAP);
    texture.setBoundaryModeT(Texture.WRAP);
    texture.setBoundaryColor(new Color4f(0.0f, 1.0f, 0.0f, 0.0f));

    // Set up the texture attributes
    //could be REPLACE, BLEND or DECAL instead of MODULATE
    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.MODULATE);
    Appearance ap = new Appearance();
    ap.setTexture(texture);//from  w  ww . j ava2  s .c o m
    ap.setTextureAttributes(texAttr);

    //set up the material
    ap.setMaterial(new Material(red, black, red, black, 1.0f));

    // Create a ball to demonstrate textures
    int primflags = Primitive.GENERATE_NORMALS + Primitive.GENERATE_TEXTURE_COORDS;
    Sphere sphere = new Sphere(0.5f, primflags, ap);
    group.addChild(sphere);

    // Create lights
    Color3f light1Color = new Color3f(1f, 1f, 1f);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    group.addChild(light1);

    AmbientLight ambientLight = new AmbientLight(new Color3f(.5f, .5f, .5f));
    ambientLight.setInfluencingBounds(bounds);
    group.addChild(ambientLight);

    // look towards the ball
    universe.getViewingPlatform().setNominalViewingTransform();

    // add the group of objects to the Universe
    universe.addBranchGraph(group);
}

From source file:net.erdfelt.android.sdkfido.ui.SdkFidoFrame.java

private Component createBody() {
    Container body = new Container();

    body.setLayout(new GridBagLayout());
    JTabbedPane tabs = new JTabbedPane();

    tabs.addTab("SDKs", createSdkPanel());
    tabs.addTab("Work Dir", createWorkDirPanel());

    body.add(tabs, new GBC().fillWide().margin(5, 5, 5, 5).endRow());
    body.add(createConsolePane(), new GBC().fillBoth().margin(0, 5, 5, 5).weightTall(1.0).endBoth());

    return body;//from w w  w.  ja v  a 2s  . c om
}

From source file:opendial.gui.utils.DistributionViewer.java

/**
 * Constructs or update the current viewer with the distribution.
 * //www .ja va 2 s.co  m
 * @param currentState the updated dialogue state
 */
protected void update(DialogueState currentState) {

    if (!currentState.hasChanceNode(queryVar)) {
        return;
    } else if (lastDistrib != null
            && this.lastDistrib.equals(currentState.getChanceNode(queryVar).getDistrib())) {
        return;
    }
    this.lastDistrib = currentState.queryProb(queryVar);

    Container container = new Container();
    container.setLayout(new BorderLayout());
    container.add(new JLabel("        "), BorderLayout.NORTH);
    container.add(new JLabel("        "), BorderLayout.WEST);
    container.add(new JLabel("        "), BorderLayout.EAST);
    container.add(new JLabel("        "), BorderLayout.SOUTH);

    try {
        IndependentDistribution indepDistrib = currentState.queryProb(queryVar);
        if (indepDistrib instanceof ContinuousDistribution) {
            container.add(generatePanel(indepDistrib.toContinuous()), BorderLayout.CENTER);
        } else {
            container.add(generatePanel(indepDistrib.toDiscrete()), BorderLayout.CENTER);
        }
    } catch (RuntimeException e) {
        log.warning("could not generate distribution viewer: " + e);
    }
    setContentPane(container);
    if (getSize().height == 0 || getSize().width == 0) {
        pack();
        setLocation(new Random().nextInt(500), (new Random()).nextInt(500));
        setVisible(true);
    } else {
        validate();
    }
}

From source file:opendial.gui.stateviewer.DistributionViewer.java

/**
 * Constructs or update the current viewer with the distribution.
 * /* ww w.  jav a  2  s.  c om*/
 * @param currentState the updated dialogue state
 */
protected void update(DialogueState currentState) {

    if (!currentState.hasChanceNode(queryVar)) {
        return;
    } else if (lastDistrib != null
            && this.lastDistrib.equals(currentState.getChanceNode(queryVar).getDistrib())) {
        return;
    }
    this.lastDistrib = currentState.queryProb(queryVar);

    Container container = new Container();
    container.setLayout(new BorderLayout());
    container.add(new JLabel("        "), BorderLayout.NORTH);
    container.add(new JLabel("        "), BorderLayout.WEST);
    container.add(new JLabel("        "), BorderLayout.EAST);
    container.add(new JLabel("        "), BorderLayout.SOUTH);

    try {
        IndependentProbDistribution indepDistrib = currentState.queryProb(queryVar);
        if (indepDistrib instanceof ContinuousDistribution) {
            container.add(generatePanel(indepDistrib.toContinuous()), BorderLayout.CENTER);
        } else {
            container.add(generatePanel(indepDistrib.toDiscrete()), BorderLayout.CENTER);
        }
    } catch (DialException e) {
        log.warning("could not generate distribution viewer: " + e);
    }
    setContentPane(container);
    if (getSize().height == 0 || getSize().width == 0) {
        pack();
        setLocation(new Random().nextInt(500), (new Random()).nextInt(500));
        setVisible(true);
    } else {
        validate();
    }
}

From source file:com.cubusmail.server.services.RetrieveImageServlet.java

/**
 * @param bufInputStream/*from  w ww  .j a v a 2 s.co  m*/
 * @param outputStream
 */
private void writeScaledImage(BufferedInputStream bufInputStream, OutputStream outputStream) {

    long millis = System.currentTimeMillis();
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        int bytesRead = 0;
        byte[] buffer = new byte[8192];
        while ((bytesRead = bufInputStream.read(buffer, 0, 8192)) != -1) {
            bos.write(buffer, 0, bytesRead);
        }
        bos.close();

        byte[] imageBytes = bos.toByteArray();

        Image image = Toolkit.getDefaultToolkit().createImage(imageBytes);
        MediaTracker mediaTracker = new MediaTracker(new Container());
        mediaTracker.addImage(image, 0);
        mediaTracker.waitForID(0);
        // determine thumbnail size from WIDTH and HEIGHT
        int thumbWidth = 300;
        int thumbHeight = 200;
        double thumbRatio = (double) thumbWidth / (double) thumbHeight;
        int imageWidth = image.getWidth(null);
        int imageHeight = image.getHeight(null);
        double imageRatio = (double) imageWidth / (double) imageHeight;
        if (thumbRatio < imageRatio) {
            thumbHeight = (int) (thumbWidth / imageRatio);
        } else {
            thumbWidth = (int) (thumbHeight * imageRatio);
        }
        // draw original image to thumbnail image object and
        // scale it to the new size on-the-fly
        BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB);
        Graphics2D graphics2D = thumbImage.createGraphics();
        graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);

        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(outputStream);
        JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);
        int quality = 70;
        quality = Math.max(0, Math.min(quality, 100));
        param.setQuality((float) quality / 100.0f, false);
        encoder.setJPEGEncodeParam(param);
        encoder.encode(thumbImage);
    } catch (IOException ex) {
        log.error(ex.getMessage(), ex);
    } catch (InterruptedException ex) {
        log.error(ex.getMessage(), ex);
    } finally {
        log.debug("Time for thumbnail: " + (System.currentTimeMillis() - millis) + "ms");
    }
}

From source file:misc.ModalityDemo.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method is invoked from the/*from  www .  jav  a 2  s .c  om*/
 * event-dispatching thread.
 */
private void createAndShowGUI() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    Insets ins = Toolkit.getDefaultToolkit().getScreenInsets(gc);
    int sw = gc.getBounds().width - ins.left - ins.right;
    int sh = gc.getBounds().height - ins.top - ins.bottom;

    // first document

    // frame f1

    f1 = new JFrame("Book 1 (parent frame)");
    f1.setBounds(32, 32, 300, 200);
    f1.addWindowListener(closeWindow);
    // create radio buttons
    rb11 = new JRadioButton("Biography", true);
    rb12 = new JRadioButton("Funny tale", false);
    rb13 = new JRadioButton("Sonnets", false);
    // place radio buttons into a single group
    ButtonGroup bg1 = new ButtonGroup();
    bg1.add(rb11);
    bg1.add(rb12);
    bg1.add(rb13);
    JButton b1 = new JButton("OK");
    b1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // get label of selected radiobutton
            String title = null;
            if (rb11.isSelected()) {
                title = rb11.getText();
            } else if (rb12.isSelected()) {
                title = rb12.getText();
            } else {
                title = rb13.getText();
            }
            // prepend radio button label to dialogs' titles
            d2.setTitle(title + " (modeless dialog)");
            d3.setTitle(title + " (document-modal dialog)");
            d2.setVisible(true);
        }
    });
    Container cp1 = f1.getContentPane();
    // create three containers to improve layouting
    cp1.setLayout(new GridLayout(1, 3));
    // an empty container
    Container cp11 = new Container();
    // a container to layout components
    Container cp12 = new Container();
    // an empty container
    Container cp13 = new Container();
    // add a button into a separate panel
    JPanel p1 = new JPanel();
    p1.setLayout(new FlowLayout());
    p1.add(b1);
    // add radio buttons and the OK button one after another into a single column
    cp12.setLayout(new GridLayout(4, 1));
    cp12.add(rb11);
    cp12.add(rb12);
    cp12.add(rb13);
    cp12.add(p1);
    // add three containers
    cp1.add(cp11);
    cp1.add(cp12);
    cp1.add(cp13);

    // dialog d2

    d2 = new JDialog(f1);
    d2.setBounds(132, 132, 300, 200);
    d2.addWindowListener(closeWindow);
    JLabel l2 = new JLabel("Enter your name: ");
    l2.setHorizontalAlignment(SwingConstants.CENTER);
    tf2 = new JTextField(12);
    JButton b2 = new JButton("OK");
    b2.setHorizontalAlignment(SwingConstants.CENTER);
    b2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //pass a name into the document modal dialog
            l3.setText("by " + tf2.getText());
            d3.setVisible(true);
        }
    });
    Container cp2 = d2.getContentPane();
    // add label, text field and button one after another into a single column
    cp2.setLayout(new BorderLayout());
    cp2.add(l2, BorderLayout.NORTH);
    cp2.add(tf2, BorderLayout.CENTER);
    JPanel p2 = new JPanel();
    p2.setLayout(new FlowLayout());
    p2.add(b2);
    cp2.add(p2, BorderLayout.SOUTH);

    // dialog d3

    d3 = new JDialog(d2, "", Dialog.ModalityType.DOCUMENT_MODAL);
    d3.setBounds(232, 232, 300, 200);
    d3.addWindowListener(closeWindow);
    JTextArea ta3 = new JTextArea();
    l3 = new JLabel();
    l3.setHorizontalAlignment(SwingConstants.RIGHT);
    Container cp3 = d3.getContentPane();
    cp3.setLayout(new BorderLayout());
    cp3.add(new JScrollPane(ta3), BorderLayout.CENTER);
    JPanel p3 = new JPanel();
    p3.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p3.add(l3);
    cp3.add(p3, BorderLayout.SOUTH);

    // second document

    // frame f4

    f4 = new JFrame("Book 2 (parent frame)");
    f4.setBounds(sw - 300 - 32, 32, 300, 200);
    f4.addWindowListener(closeWindow);
    // create radio buttons
    rb41 = new JRadioButton("Biography", true);
    rb42 = new JRadioButton("Funny tale", false);
    rb43 = new JRadioButton("Sonnets", false);
    // place radio buttons into a single group
    ButtonGroup bg4 = new ButtonGroup();
    bg4.add(rb41);
    bg4.add(rb42);
    bg4.add(rb43);
    JButton b4 = new JButton("OK");
    b4.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // get label of selected radiobutton
            String title = null;
            if (rb41.isSelected()) {
                title = rb41.getText();
            } else if (rb42.isSelected()) {
                title = rb42.getText();
            } else {
                title = rb43.getText();
            }
            // prepend radiobutton label to dialogs' titles
            d5.setTitle(title + " (modeless dialog)");
            d6.setTitle(title + " (document-modal dialog)");
            d5.setVisible(true);
        }
    });
    Container cp4 = f4.getContentPane();
    // create three containers to improve layouting
    cp4.setLayout(new GridLayout(1, 3));
    Container cp41 = new Container();
    Container cp42 = new Container();
    Container cp43 = new Container();
    // add the button into a separate panel
    JPanel p4 = new JPanel();
    p4.setLayout(new FlowLayout());
    p4.add(b4);
    // add radiobuttons and the OK button one after another into a single column
    cp42.setLayout(new GridLayout(4, 1));
    cp42.add(rb41);
    cp42.add(rb42);
    cp42.add(rb43);
    cp42.add(p4);
    //add three containers
    cp4.add(cp41);
    cp4.add(cp42);
    cp4.add(cp43);

    // dialog d5

    d5 = new JDialog(f4);
    d5.setBounds(sw - 400 - 32, 132, 300, 200);
    d5.addWindowListener(closeWindow);
    JLabel l5 = new JLabel("Enter your name: ");
    l5.setHorizontalAlignment(SwingConstants.CENTER);
    tf5 = new JTextField(12);
    tf5.setHorizontalAlignment(SwingConstants.CENTER);
    JButton b5 = new JButton("OK");
    b5.setHorizontalAlignment(SwingConstants.CENTER);
    b5.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //pass a name into the document modal dialog
            l6.setText("by " + tf5.getText());
            d6.setVisible(true);
        }
    });
    Container cp5 = d5.getContentPane();
    // add label, text field and button one after another into a single column
    cp5.setLayout(new BorderLayout());
    cp5.add(l5, BorderLayout.NORTH);
    cp5.add(tf5, BorderLayout.CENTER);
    JPanel p5 = new JPanel();
    p5.setLayout(new FlowLayout());
    p5.add(b5);
    cp5.add(p5, BorderLayout.SOUTH);

    // dialog d6

    d6 = new JDialog(d5, "", Dialog.ModalityType.DOCUMENT_MODAL);
    d6.setBounds(sw - 500 - 32, 232, 300, 200);
    d6.addWindowListener(closeWindow);
    JTextArea ta6 = new JTextArea();
    l6 = new JLabel();
    l6.setHorizontalAlignment(SwingConstants.RIGHT);
    Container cp6 = d6.getContentPane();
    cp6.setLayout(new BorderLayout());
    cp6.add(new JScrollPane(ta6), BorderLayout.CENTER);
    JPanel p6 = new JPanel();
    p6.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p6.add(l6);
    cp6.add(p6, BorderLayout.SOUTH);

    // third document

    // frame f7

    f7 = new JFrame("Classics (excluded frame)");
    f7.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
    f7.setBounds(32, sh - 200 - 32, 300, 200);
    f7.addWindowListener(closeWindow);
    JLabel l7 = new JLabel("Famous writers: ");
    l7.setHorizontalAlignment(SwingConstants.CENTER);
    // create radio buttons
    rb71 = new JRadioButton("Burns", true);
    rb72 = new JRadioButton("Dickens", false);
    rb73 = new JRadioButton("Twain", false);
    // place radio buttons into a single group
    ButtonGroup bg7 = new ButtonGroup();
    bg7.add(rb71);
    bg7.add(rb72);
    bg7.add(rb73);
    Container cp7 = f7.getContentPane();
    // create three containers to improve layouting
    cp7.setLayout(new GridLayout(1, 3));
    Container cp71 = new Container();
    Container cp72 = new Container();
    Container cp73 = new Container();
    // add the label into a separate panel
    JPanel p7 = new JPanel();
    p7.setLayout(new FlowLayout());
    p7.add(l7);
    // add a label and radio buttons one after another into a single column
    cp72.setLayout(new GridLayout(4, 1));
    cp72.add(p7);
    cp72.add(rb71);
    cp72.add(rb72);
    cp72.add(rb73);
    // add three containers
    cp7.add(cp71);
    cp7.add(cp72);
    cp7.add(cp73);

    // fourth document

    // frame f8

    f8 = new JFrame("Feedback (parent frame)");
    f8.setBounds(sw - 300 - 32, sh - 200 - 32, 300, 200);
    f8.addWindowListener(closeWindow);
    JButton b8 = new JButton("Rate yourself");
    b8.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showConfirmDialog(null, "I really like my book", "Question (application-modal dialog)",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        }
    });
    Container cp8 = f8.getContentPane();
    cp8.setLayout(new FlowLayout(FlowLayout.CENTER, 8, 8));
    cp8.add(b8);
}

From source file:com.schnee.tweetgeister.visualization.TweetgeisterBalloonLayout.java

private void writeGraph() {
    Container c = new Container();

    VisualizationViewer<Node, Integer> vv = new VisualizationViewer<Node, Integer>(balloonLayout,
            new Dimension(3000, 3000));
    vv.setBackground(Color.white);
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line());
    vv.getRenderContext().setVertexLabelTransformer(new TopicNodeLabeller(graph));
    vv.getRenderContext().setVertexIncludePredicate(new VertexDisplayPredicate(false));
    // add a listener for ToolTips
    vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));
    //vv.addPreRenderPaintable(rings);
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);
    rings = new Rings(balloonLayout, vv);
    vv.addPreRenderPaintable(rings);/* w  ww . java  2s. com*/
    java.awt.image.BufferedImage bi = new java.awt.image.BufferedImage(3000, 3000,
            java.awt.image.BufferedImage.TYPE_INT_RGB);

    Graphics2D gr = bi.createGraphics();

    // MOST-IMPORTANT

    vv.setSize(3000, 3000);

    final ScalingControl scaler = new CrossoverScalingControl();

    vv.scaleToLayout(scaler);

    // MOST-IMPORTANT

    c.addNotify();

    c.add(vv);

    c.setVisible(true);

    c.paintComponents(gr);

    try {
        ImageIO.write(bi, "png", new File("vis.png"));
        System.out.println("done");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}