Bug in Flow layout?

Before I made a JIRA entry, wanted to see if anyone else thought this was a bug. It drove me crazy for days.
It appears that if I initialize a Flow content at the time of creation of the Flow object, all is well. However, if I add content in bulk afterwards, all elements are stacked on top of each other. Other layouts (like HBox seem to work just fine). More interestingly, 'later' if I add or remove elements from the flow, it adjusts its size and positions of everything correctly. Weird.
This works fine:
function createFlow():Flow{
    var flow:Flow = Flow{
         width: 100 hgap: 5 vgap: 10
         content: for (i in [1..5])
         Rectangle { width: 40 height: 40 }
Stage {
    scene: Scene {
        content: [
             createFlow()
}However, this way stacks the rectangles on top of each other for some reason.
function createFlow():Flow{
    var flow:Flow = Flow{
         width: 100 hgap: 5 vgap: 10
     for (i in [1..5])
         insert Rectangle { width: 40 height: 40 } into flow.content;
    return flow;
Stage {
    scene: Scene {
        content: [
             createFlow()
}

Indeed, it sounds as a bug H/VBox had in 1.1.
I can reproduce your problem with JavaFX 1.2 on Windows XP Pro SP3.
The following code works fine too:
Stage {
    scene: Scene {
        content: [
//~             createFlow()
               Flow {
                    width: 100 hgap: 5 vgap: 10
                    content: for (i in [1..5])
                         Rectangle { width: 40 height: 40 }
}but this one fails:
function createFlow(): Flow {
    var flow: Flow = Flow {
        width: 100 hgap: 5 vgap: 10
    var content = for (i in [1..5])
          Rectangle { width: 40 height: 40 };
    flow.content = content;
    return flow;
}Looks like Flow prefers to have its sequence provided at creation time...

Similar Messages

  • Another bug in Flow layout ?

    If a Flow object gets its content during initialization it doesn't take the specified size of the children into account. The sizes are kept if the children are added afterwards. But then they're stacked on top of each other; as described in the other thread.
    Example: The buttons sizes are ignored.
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.layout.Flow;
    import javafx.scene.control.*;
    def okButton = Button {
        text: "OK"
        strong: true
        width: 100
        height: 100
    def cancelButton = Button {
        text: "Cancel"
        width: 100
        height: 100
    def layout = Flow {
        content: [okButton, cancelButton];
    Stage {
        title: "Flowlayout Demo"
        scene: Scene {
            width: 400
            height: 400
            content: layout
    }Example: The sizes are not ignored, but the positions are.
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.layout.Flow;
    import javafx.scene.control.*;
    def okButton = Button {
        text: "OK"
        strong: true
        width: 100
        height: 100
    def cancelButton = Button {
        text: "Cancel"
        width: 100
        height: 100
    def layout = Flow {};
    layout.content = [okButton, cancelButton];
    Stage {
        title: "JavaFX 1.2 Controls Demo"
        scene: Scene {
            width: 400
            height: 400
            content: layout
    }

    CORRECTION: It works if a child gets a LayoutInfo object. False alarm. MEA CULPA.
    def largeButtonDimension = LayoutInfo {
          width: 100
          height: 100
          minWidth: 100
          minHeight: 100
    def smallButtonDimension = LayoutInfo {
          width: 50
          height: 50
          minWidth: 50
          minHeight: 50
    def okButton = Button {
        text: "OK"
        layoutInfo: largeButtonDimension;
        strong: true
    def cancelButton = Button {
        text: "Cancel"
        layoutInfo: smallButtonDimension
    def layout = Flow {
        content: [okButton, cancelButton];
    }

  • Flow Layout

    Hey,
    i got a little problem. I need to write a clozeTest in JavaFx and it´s not function like i want.
    The problem that i have, is that the text shouldn´t start on a new line in case he hasn´t enough place.
    * clozeStage.fx
    * Created on 03.06.2010, 13:17:03
    package progressbar;
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.text.Text;
    import javafx.scene.text.Font;
    import javafx.ext.swing.SwingTextField;
    import javafx.scene.layout.Flow;
    import javafx.scene.shape.Ellipse;
    import javafx.scene.paint.Color;
    import javafx.geometry.HPos;
    import javafx.scene.layout.Tile;
    import javafx.scene.layout.HBox;
    import javafx.scene.Group;
    import javafx.scene.layout.VBox;
    * @author Dori
    var tf: SwingTextField[];
    var luecken: String [];
    var test:Boolean;
    luecken = ["Ich werde gleich ausflippen. Ich","(lernen) dieses JavaFX. Ich finde das echt toll. Außerdem werde ich jetzt mal ein bisschen extrem langen dummen Text schreiben, damit ich überprüfen kann, ob das gute FlowLayout auch einen Umbruch macht.",
                "Das ist ein Test, ob er auch"," automatisch zwischen Wörtern trennen kann.", " Voila", "Ohyeah"];
    for(i in [0..10]){
         tf=SwingTextField {
         columns: 5
         text: ""
         editable: true
    Stage {
    title: "Application title"
    scene: Scene {
    width: 900
    height: 400
    content: [
    Flow{
    width:700
    hpos: HPos.LEFT
    content:[
    for (m in [0..20]){
    if(test == false){
    test = true;
    Text{
    content: luecken[m/2]
    font: Font{size:15}
    wrappingWidth:700
    else{
    test = false;
    tf[m]
    It would be nice if somebody could help me.
    Edited by: avalonne on Jun 7, 2010 3:51 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Answered (I think) in the second [Flow Layout|http://forums.sun.com/thread.jspa?threadID=5441485] topic.

  • White space after flowed layout/expandable fields?

    Hi,
    I have a few pages on a form with a flowed layout where the text fields expand.The problem I am having is when the text field expans and continues on the following page,its leazing an entire white space right after it.Is there a way to do this so eventhough the text field expands onto the next page,the content on the next page continues right after the expanded field without a page of white space?
    Thanks.

    Hi,
    You need to check Allow page breaks within content option for the subform. Object > Subform >  Allow page breaks within content.
    By default even for the field this option would be checked if it is not You need to do samething even for the field.
    This would work.
    -Vjay

  • GridBag or Flow Layout: Help Please!!!

    Requirement: Allow the user to input the amount of a mortgage and then select from a menu of mortgage loans: 7 years at 5.35%, 15 years at 5.5%, and 30 years at 5.75%. Use an array for the different loans. Display the mortgage payment amount. Then, list the loan balance and interest paid for each payment over the term of the loan. Allow the user to loopback and enter a new amount and make a new selection or quit.
    I have written the code so far that allows for the creation of the pane, texts, user entry, combobox, and buttons.
    My problem is that I cannot get it sorted out to look like a usable interface. I don't know if I should go with a GridBag Layout or a Flow Layout.
    I am using the GridBag Layout in this example, but obviously I am missing the correct procedure on how to do it.
    Can anyone give me a hand?
    My goal for the interface is to have the following fields set up in the pane to lay out like this:
    Mortgage ------ MortgageTF
    Loan ----- LoanCB
    Payment ----- PaymentTF
    Balance
    Compute----- Reset----- Exit
    Thank you for any assistance.
    Havok
    My written code is below:
    import javax.swing.*;
    import java.awt.*;
    public class MCalc002 extends JFrame
    public MCalc002()
    super("Mortgage Calculator");
    setSize(500, 800);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
    Container pane = getContentPane();
    GridBagLayout gridBag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    pane.setLayout(gridBag);
    JLabel mortgage = new JLabel("Mortgage:");
    c.gridx = 0; c.gridy = 0;
    pane.add(mortgage);
    JLabel loan = new JLabel("Loan Menu:");
    c.gridx = 2; c.gridy = 2;
    pane.add(loan);
    JLabel payment = new JLabel("Monthly Payment:");
    c.gridx = 3; c.gridy = 3;
    pane.add(payment);
    JLabel balance = new JLabel("Loan Balance:");
    c.gridx = 4; c.gridy = 4;
    pane.add(balance);
    JTextField mortgageTF = new JTextField(10);
    c.gridx = 4; c.gridy = 4;
    pane.add(mortgageTF);
    JComboBox loanCB = new JComboBox();
    c.gridx = 5; c.gridy = 5;
    loanCB.addItem("Please Select");
    loanCB.addItem("7yrs @ 5.35%");
    loanCB.addItem("15yrs @ 5.5%");
    loanCB.addItem("30yrs @ 5.75%");
    pane.add(loanCB);
    JTextField paymentTF= new JTextField(10);
    c.gridx = 4; c.gridy = 4;
    pane.add(paymentTF);
    JButton compute = new JButton("Compute");
    c.gridx = 5; c.gridy = 5;
    pane.add(compute, c);
    JButton reset = new JButton("Reset");
    c.gridx = 6; c.gridy = 6;
    pane.add(reset, c);
    JButton exit = new JButton("Exit");
    c.gridx = 7; c.gridy = 7;
    pane.add(exit, c);
    setContentPane(pane);
    public static void main(String[] arguments)
    MCalc002 pb = new MCalc002();
    //EOF

    My problem is that I cannot get it sorted out to look
    like a usable interface. I don't know if I should go
    with a GridBag Layout or a Flow Layout.
    My goal for the interface is to have the following
    fields set up in the pane to lay out like this:
    Mortgage ------ MortgageTF
    Loan ----- LoanCB
    Payment ----- PaymentTF
    Balance
    Compute----- Reset----- Exit
    import javax.swing.*;
    import java.awt.*;
    public class MCalc002 extends JFrame {
        public MCalc002() {
            super("Mortgage Calculator");
            setSize(500, 800);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            Container pane = getContentPane();
            GridBagLayout gridBag = new GridBagLayout();
            GridBagConstraints c = new GridBagConstraints();
            pane.setLayout(gridBag);
            JLabel mortgage = new JLabel("Mortgage:");
            c.gridx = 0; c.gridy = 0;
            c.insets = new Insets(20,10,20,10);
            gridBag.setConstraints(mortgage, c);
            pane.add(mortgage);
            JLabel loan = new JLabel("Loan Menu:");
            c.gridx = 0; c.gridy = 1;
            c.insets = new Insets(20,10,20,10);
            gridBag.setConstraints(loan, c);
            pane.add(loan);
            JLabel payment = new JLabel("Monthly Payment:");
            c.gridx = 0; c.gridy = 2;
            c.insets = new Insets(20,10,20,10);
            gridBag.setConstraints(payment, c);
            pane.add(payment);
            JLabel balance = new JLabel("Loan Balance:");
            c.gridx = 0; c.gridy = 3;
            c.insets = new Insets(20,10,20,10);
            gridBag.setConstraints(balance, c);
            pane.add(balance);
            JTextField mortgageTF = new JTextField(10);
            c.gridx = 3; c.gridy = 0;
            c.insets = new Insets(20,10,20,10);
            gridBag.setConstraints(mortgageTF, c);
            pane.add(mortgageTF);
            JComboBox loanCB = new JComboBox();
            c.gridx = 3; c.gridy = 1;
            c.insets = new Insets(20,10,20,10);
            loanCB.addItem("Please Select");
            loanCB.addItem("7yrs @ 5.35%");
            loanCB.addItem("15yrs @ 5.5%");
            loanCB.addItem("30yrs @ 5.75%");
            gridBag.setConstraints(loanCB, c);
            pane.add(loanCB);
            JTextField paymentTF= new JTextField(10);
            c.gridx = 3; c.gridy = 2;
            c.insets = new Insets(20,10,20,10);
            gridBag.setConstraints(paymentTF, c);
            pane.add(paymentTF);
            JButton compute = new JButton("Compute");
            c.gridx = 0; c.gridy = 4;
            c.insets = new Insets(20,10,20,10);
            gridBag.setConstraints(compute, c);
            pane.add(compute, c);
            JButton reset = new JButton("Reset");
            c.gridx = 1; c.gridy = 4;
            c.insets = new Insets(20,10,20,10);
            gridBag.setConstraints(reset, c);
            pane.add(reset, c);
            JButton exit = new JButton("Exit");
            c.gridx = 3; c.gridy = 4;
            c.insets = new Insets(20,10,20,10);
            gridBag.setConstraints(exit, c);
            pane.add(exit, c);
            setContentPane(pane);
            setVisible(true);  // Generally speaking, this should be the last operation in setting up GUI components.
        public static void main(String[] arguments) {
            MCalc002 pb = new MCalc002();
    }

  • ITextSharp and Flow Layout

    I am filling out a form using iTextSharp . I have a flow layout subform with a multiline textbox on the form, expand to fit set to true. Still, when I insert text into the textbox programmatically, it does not expand. If I fill out the pdf form interactively, it works fine.
    Any help would be appreciated.
    Thanks

    I use the Acrofields.SetField method ,like this:
    AcroFields pdfFormFields = pdfStamper.AcroFields;
    foreach (PrintableFormDataField dataField in _DataFields)
    pdfFormFields.SetField(dataField.DataLabel, dataField.DataValue);

  • Span div problem on flow layout

    i want to use flow layout for my page. if there is any component that includes div tag it causes new line on html page. i use page fragments in my page. if there is any fragment that includes div tag next component appears on new line. i want to place more than one components in the same line. how can i do that?

    Hi!
    You can play with mode of position property. Open 'style' property, select 'Position' part and try to change 'Mode'.
    Thanks,
    Roman.

  • Spacing JButtons on Flow Layout....

    Hello,
    I am a Java student. The assignment was to create a calculator. I have just begun the layout portion (to me the hardest part).... I decided to go with Flow Layout due to its easiest nature to a beginner.
    Here is the code i have so far:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Calculator extends JFrame
         public static final int width = 300;
         public static final int height = 260;
         public static void main(String[] args)
              Calculator gui = new Calculator();
              gui.setVisible(true);
         public Calculator()
              setSize(width, height);
              addWindowListener(new WindowDestroyer());
              setTitle("Calculator");
              Container contentPane = getContentPane();
              contentPane.setLayout(new FlowLayout());
              contentPane.setBackground(Color.LIGHT_GRAY);
              JPanel aPanel = new JPanel();
              JTextField display = new JTextField(25);
              contentPane.add(aPanel);
              aPanel.add(display);
              JPanel anotherPanel = new JPanel();
              contentPane.add(anotherPanel);
              JButton backspace = new JButton("Backspace");
              contentPane.add(backspace);
              JButton clearEntry = new JButton("CE");
              contentPane.add(clearEntry);
              JButton clear = new JButton("C");
              contentPane.add(clear);
              JButton mc = new JButton("MC");
              contentPane.add(mc);
              JButton sevenButton = new JButton("7");
              contentPane.add(sevenButton);
              JButton eightButton = new JButton("8");
              contentPane.add(eightButton);
              JButton nineButton = new JButton("9");
              contentPane.add(nineButton);
              JButton divide = new JButton("/");
              contentPane.add(divide);
              JButton sqrt = new JButton("sqrt");
              contentPane.add(sqrt);
              JButton mr = new JButton("MR");
              contentPane.add(mr);
              JButton fourButton = new JButton("4");
              contentPane.add(fourButton);
              JButton fiveButton = new JButton("5");
              contentPane.add(fiveButton);
              JButton sixButton = new JButton("6");
              contentPane.add(sixButton);
              JButton multiply = new JButton("*");
              contentPane.add(multiply);
              JButton percent = new JButton("%");
              contentPane.add(percent);
              JButton ms = new JButton("MS");
              contentPane.add(ms);
              JButton oneButton = new JButton("1");
              contentPane.add(oneButton);
              JButton twoButton = new JButton("2");
              contentPane.add(twoButton);
              JButton threeButton = new JButton("3");
              contentPane.add(threeButton);
              JButton minusButton = new JButton("-");
              contentPane.add(minusButton);
              JButton reciprocal = new JButton("1/x");
              contentPane.add(reciprocal);
              JButton mplus = new JButton("M+");
              contentPane.add(mplus);
              JButton zeroButton = new JButton("0");
              contentPane.add(zeroButton);
              JButton plusMinus = new JButton("+/-");
              contentPane.add(plusMinus);
              JButton dotButton = new JButton(".");
              contentPane.add(dotButton);
              JButton additionButton = new JButton("+");
              contentPane.add(additionButton);
              JButton equalsButton = new JButton("=");
              contentPane.add(equalsButton);
    Keep in mind i will do the action listeners and everything later..... i am NOT looking for anyone to do coding for me, but here's what i would like if at all possible:
    the assignment calls for the calculator to visually appear similar/just like the windows calculator..... so in other words i need the "MC" button to start the second line, MR button to start the third, etc....
    My text book, Introduction to Java by Walter Savitch, explains Swing and JButtons, but at no time provides an example with buttons on more than one line, or how to create a new line.
    **Keep in mind this is not for an applet!!!**
    I appreciate all your help!
    -ABT-

    i almost forgot to mention what the problem was...
    with Flowlayout, it prints the buttons in order, but just as many can fit on one line.... so when you compile and run the code, the MC button appears on the first line with the 7 button starting the second line....
    I need to figure out how to insert a (web-equivalent) <br> in the code, to tell the swing module to start a new line for the next set of JButtons.
    thanks
    -ABT-

  • How to ensure Flow Layout wraps contents

    hi,
    having problems with flow layout (in Applet), i can not make it wrap the contents when the window is resized. it just seems to insist that everything be on one line.
    yet i have examples from others that wrap fine. and i believe i am doing everything correct.
    So what's the trick to getting the wrap, and why?

    first thing to say about the flowklayout is that
    1.it respects the componetnt prefered size.
    2.It will arrange the components in one line ( one after another ) respectivily. so the components will appear in the order that you have added them.
    3.it will move the components under each other, each time you try to minimize the Frame or applet, so if the frame or applet is not big enought to be as wide as all the components prefered size it will drop down the least component.
    so it might be better to try another layout, let say BorderLayout. it meight be better.

  • Distance between buttons (Flow Layout)

    Hi people,
    I Have 100 buttons inside a JPane with Flow Layout.
    How do I set the distance between the buttons to 0(width and height)?
    Regards.
    Thank's.

    Yes, I did!
    I have a class "Board" that extends JPanel with GridLayout.
    This class has a constructor that takes the rows, cols, number of mines and size of squares!
    package view;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.util.Random;
    import javax.swing.JPanel;
    import model.Square;
    import control.SquareHandler;
    public class Board extends JPanel {
         private Square square[][] = new Square[16][30];
         private int mines, width, height;
         Board(int width, int height, int mines, int size) {
              Dimension dimension = new Dimension(size,size);
              //FlowLayout layout = new FlowLayout();
              GridLayout layout = new GridLayout();
              //layout.setHgap(0);
              //layout.setVgap(0);
              layout.setRows(height);
              layout.setColumns(width);
              this.mines = mines;
              this.width = width;
              this.height = height;
              setLayout(layout);
              for (int j = 0; j < height; j++){
                   for (int i = 0; i < width; i++){
                        square[j] = new Square(i,j);
                        square[j][i].setPreferredSize(dimension);
                        square[j][i].addActionListener(new SquareHandler(this, i, j));
                        add(square[j][i]);
              makeMines();
         public void makeMines() {
              Random randomizer = new Random();
              int randomX, randomY;
              for (int i = 0; i < mines; i++){
                   while (true) {
                        randomX = randomizer.nextInt();
                        randomX = Math.abs(randomX);
                        randomX = randomX % width;
                        randomY = randomizer.nextInt();
                        randomY = Math.abs(randomY);
                        randomY = randomY % height;
                        if(!square[randomY][randomX].getMine()){
                             square[randomY][randomX].setMine();
                             break;
         public Square getSquare(int x, int y){
              if (x < 0 || x >= width || y < 0 || y >= height ){
                   // Error
                   return new Square(-1,-1);
              return square[y][x];

  • WLP 10 & Flow Layout

    Hi,
    i need a page with a horizontal flow layout (2 portlets side by side).
    I've created a new layout which works fine with the classic or default
    laf but not with bighorn.
    Any suggestion about this issue ?
    Thx

    Hi Emmanuel,
    Try creating a file /WebContent/framework/markup/layouts/onerowflow.layout with this content:
    <?xml version="1.0" encoding="UTF-8"?>
    <netuix:markupDefinition xmlns:netuix="http://www.bea.com/servers/netuix/xsd/controls/netuix/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/servers/netuix/xsd/controls/netuix/1.0.0 markup-netuix-1_0_0.xsd">
        <netuix:locale language="en"/>
        <netuix:markup>
            <netuix:flowLayout
                               title="One Row Flow Layout" description="This layout uses the flowLayout control to create one row in which placeables flow horizontally."
                               orientation="horizontal" htmlLayoutUri="/framework/markup/layout/onerowflow.html.txt" iconUri="/framework/markup/layout/singlecolumn.gif"
                               markupType="Layout" markupName="oneRowFlowLayout">
                <netuix:placeholder title="center" description="The only placeholder in this layout."
                                    usingFlow="true" width="100%" flow="horizontal"
                                    markupType="Placeholder" markupName="oneRowFlow_center">
                </netuix:placeholder>
            </netuix:flowLayout>
        </netuix:markup>
    </netuix:markupDefinition>And also /WebContent/framework/markup/layouts/onerowflow.html.txt with this content:
    <table class="portalLayout" id="thePortalLayout" width="100%" height="100%">
      <tr>
        <td class="placeholderTD" valign="top" width="100%">
          <placeholder number="0" flow="horizontal"/>
        </td>
      </tr>
    </table>Then change your portal page to use this new layout in Workshop, and you should be all set. Reply here if this doesn't work for you.
    George

  • ScrollPane Flow Layout

    Hi Guys,
    I am at my wits end as to how I can solve this. I really can't find a solution, I hope you can help.
    I have a gui layout thus:
    JTabbedPane -> JScrollPane -> JPanel -> JPanel (instead of awt.canvas)
    I have multiple java2d 'graphs' that I wish to layout on this scrollpane left to right which then wrap. If the screen is full, vertical scrollbars are triggered. So I think flow layout is the closest to this as I really must maintain the original component size. Grid layout etc resize the graphs making it look wrong.
    The problem is that with flow layout, it scrolls infinitely horizontally. The only way I can get to to stop scrolling harizontally is by calling setPreferedSize(). When I do this however it seems to disable the scroll bars.
    I have tried all combinations of layout managers to try and give me the same effect - to no avail. I have tried setting the scrollpane display policies and again this has no effect.
    So I suppose I can see two possibilites:
    1- find some way of getting the scrollpane to wrap without setPreferredSize()
    2- find a way of getting the scroll bars working, with setPreferredSize()
    My code, looks like this:
    scrollPaneContents_ = new JPanel();
    scrollPaneContents_.setPreferredSize(new Dimension(scrollPane_.getWidth(),scrollPane_.getHeight()));
    scrollPaneContents_.setLayout(new FlowLayout(FlowLayout.CENTER));
    scrollPane_ = new JScrollPane(scrollPaneContents_);
    //scrollPane_ = new JScrollPane(scrollPaneContents_/*,
    //scrollPane_.VERTICAL_SCROLLBAR_AS_NEEDED,scrollPane_.HORIZONTAL_SCROLLBAR_NEVER*/);
    //layout.setConstraints(scrollPane_, layoutConstraints);
    // I want it to scroll to the width less and continue downwards forever
    scrollPaneContents_.setVisible(true);
    tabView_.add("Tab Name",scrollPane_);
    tabView_.refresh();
    view_.refresh();
    scrollPaneContents_.add(graphView_);
    As you can see I have commented some out to try every combination :)
    Any suggestions?
    TIA

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class GridBagAddition
        public static void main(String[] args)
            DisplayPanel displayPanel = new DisplayPanel();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new JScrollPane(displayPanel));
            f.getContentPane().add(displayPanel.getButtonPanel(), "South");
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
    class DisplayPanel extends JPanel
        JButton addButton;
        GridBagConstraints gbc;
        int[] gridwidths = {
            GridBagConstraints.RELATIVE, GridBagConstraints.REMAINDER
        int graphCount = 0;
        public DisplayPanel()
            addButton = new JButton("add graph");
            setLayout(new GridBagLayout());
            gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            gbc.weighty = 1.0;
            gbc.insets = new Insets(10,5,10,5);
        public JPanel getButtonPanel()
            addButton.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    gbc.gridwidth = gridwidths[graphCount++ % gridwidths.length];
                    add(new GraphPanel(), gbc);
                    revalidate();
            JPanel panel = new JPanel();
            panel.add(addButton);
            return panel;
    class GraphPanel extends JPanel
        final int PAD = 20;
        public GraphPanel()
            setPreferredSize(new Dimension(200,175));
        public void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            int width = getWidth();
            int height = getHeight();
            int x0 = PAD;
            int x1 = width - PAD;
            int y0 = height - PAD;
            int y1 = PAD;
            g2.draw(new Line2D.Double(x0, y0, x0, y1));
            g2.draw(new Line2D.Double(x0, y0, x1, y0));
           

  • Multiline flow layout question

    I have a panel with BoxLayout that has a panel with flow layout:
    class PanelA{
            private JPanel panel1 = createPanel1();
            private JPanel panel2 = .....
            public PanelA() {
                    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
                    add(panel1);
                    add(panel2);
            private JPanel createPanel1(){
                       JPanel p = new JPanel ();
                       p.setLayout (new FlowLayout(FlowLayout.LEADING));
    }I want to realize such behavior:
    When I add a label to panel1 and this label can't be shown because panel1 has no free space it should show this label on the next line. I know that flow layout is multiline and I see a new label on the next line if I dodn't add panel2. But I added panel2 and I see only one line of panel1.

    public class FileTablePanel extends JPanel {
        private FileTable fileTable;
        private NavigationBar navigation;
        public FileTablePanel() {
            setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
            addFileTable();
            addNavigationBar();
        private void addFileTable() {
            fileTable = new FileTable(ClientModel.SINGLETON.getFileTableModel());
            fileTable.getColumnModel().getColumn(0).setPreferredWidth(206);
            fileTable.getColumnModel().getColumn(1).setPreferredWidth(45);
            fileTable.getColumnModel().getColumn(2).setPreferredWidth(55);
            fileTable.getColumnModel().getColumn(3).setPreferredWidth(85);
            fileTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            fileTable.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
            JScrollPane sp = new JScrollPane(fileTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
            sp.setBorder(new EmptyBorder(0, 0, 0, 0));
            setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
            add(sp);
        private void addNavigationBar() {
            navigation = new NavigationBar();
            add(navigation);
        private class NavigationBar extends JPanel {
         public NavigationBar (){
                 FlowLayout layout = new FlowLayout(FlowLayout.LEADING);
                 setLayout(layout);
             * Changes navigation bar when table changes
             * @param e
            public void tableChanged(TableModelEvent e) {
                removeAll();
                fill();
                revalidate();
                repaint();
            private void fill() {
                FileTableModel t = (FileTableModel) fileTable.getModel();
                String[] s = t.getFolderPath();
                //add all links
                for (int i = 0; i < s.length; ++i){
                    CLink link = new CLink(new GoUpAction(times), "", "");
                    link.setText(message);
                    add (link);
    }

  • Flow Layout....please help!

    Hi all,
    I am having trouble with my flow Layout manager. As i add more and more components to the panel, I am not able to see the components unless the resize the frame, I am wondering is there a way that I can make flow Layout manager to creat a new line rather than continuing adding to one horizontal line!!!!!??????
    Thank you for your attention,
    Dan

    thank you all for all the help, however, i am still having trouble setting the layout of my control panel......
    so here is my sample code!!!
    and please correct me!!!!
    public DrawControls(DrawPanel target) {
         this.target = target;
         //setLayout( new GridBagLayout());
         //setLayout(new FlowLayout());
         setBackground(Color.white);
         target.setForeground(Color.red);
         CheckboxGroup group = new CheckboxGroup();
         Checkbox b;
         add(b = new Checkbox(null, group, false));
         b.addItemListener(this);
         b.setForeground(Color.red);
         add(b = new Checkbox(null, group, false));
         b.addItemListener(this);
         b.setForeground(Color.green);
         add(b = new Checkbox(null, group, false));
         b.addItemListener(this);
         b.setForeground(Color.blue);
         add(b = new Checkbox(null, group, false));
         b.addItemListener(this);
         b.setForeground(Color.pink);
         add(b = new Checkbox(null, group, false));
         b.addItemListener(this);
         b.setForeground(Color.orange);
         add(b = new Checkbox(null, group, true));
         b.addItemListener(this);
         b.setForeground(Color.black);
         target.setForeground(b.getForeground());
         //setLayout(new FlowLayout());
         //Line buttons
         //setLayout(new BorderLayout());
         insertLine = new Button("H.Lines");
              insertLine.addActionListener(this);
              insertLine.setBackground(Color.lightGray);
         add(insertLine);
         // String buttons
         insertVerLine = new Button("V.Lines");
         insertVerLine.addActionListener(this);
         insertVerLine.setBackground(Color.lightGray);
         add(insertVerLine);
         insertString = new Button("Descripion");
                   insertString.addActionListener(this);
                   insertString.setBackground(Color.lightGray);
         add(insertString);
         // logo button
         insertLogo = new Button("Graphics");
                   insertLogo.addActionListener(this);
                   insertLogo.setBackground(Color.lightGray);
         add(insertLogo);
         //delete button
         delete = new Button("Delete");
                   delete.addActionListener(this);
                   delete.setBackground(Color.lightGray);
         add(delete);
         //reset button
         reset = new Button("Reset");
                   reset.addActionListener(this);
                   reset.setBackground(Color.lightGray);
                   reset.setForeground(Color.red);
         add(reset);
         //label
         Label label1 = new Label("Text");
         add(label1);
         //textbox
         yourText = new TextField(10);
         //yourText.setMaximumSize(yourText.getPreferredSize());
         add(yourText);
    TextField yourText;
    Button insertLine;
    Button insertVerLine;
    Button insertString;
    Button insertLogo;
    Button delete;
    Button reset;

  • Horizontal flowed layout

    I am creating a questionnaire and I would like to form to only display answered questions when I click the generate report button.
    For example:
    If the user has a question and they have the following options:
    The user selects Not Sure.
    Currently because the subforms are all the same and the logic is to only display answered questions, the form displays:
    Is there a way that I can set up the template to move the answer to the left so that the form does not show blank/white space?
    Thanks
    Yvette

    Oh, apparently I failed to make my point clear.
    Consider this example:
    [  ] Checkbox1     [  ] Checkbox2     [   ] Checkbox3
    [  ] Checkbox4
    Whenever I click on one of those checkboxes I would like to change the height of all checkboxes in the same row (this.h = ...)
    [Why this is necessary is too complicated to explain. These are forms that are part of fairly big environment with very specific reader add-ons .....]
    Thus: If I click on checkbox2 I would like to find the checkboxes with the same vertical position (in this case: checkbox1, checkbox2 and checkbox3) to change their heights.
    As it is a flowed layout checkbox4 has slipped over onto the next row. It is vertically further down in the current layout. Therefore I do not want to change its height.
    What I need, is not really the y-attribute of the checkbox, but the vertical position in the layout. I just cannot find an attribute that delivers this information.
    Does this make it clear?

Maybe you are looking for

  • Flash audio level drop outs (Windows 8.1)

    Hey, Using adobe flash, I've been having issues with to audio nearly dropping out to nearly inaudible levels on mutiple websites. Anything that does use the flash player, it seems to be triggered when I plug in another device into the computer for us

  • How to print Barcode in development system as well as in Sandbox?

    Hi All, We want to print barcodes in development system. However, barcodes EAN13 and EAN 8 are displayed in Sandbox but not development system. Are there any specific settings to be maintained? Thanks, AP

  • Yoga Screen foil replaceable?

    Hi, I notived the anti-glare screen foil on my thinkpad yoga and eas wandering if it can be replaced by Lenovo technicians if it should get too scratched up with time? Scrat

  • Importing Transport requests

    Hi, When i click on import transport request to import the request to target system (DEV to QTY) ,what process will be happen in background. Thanku

  • Why won't the WVC80N write a motion-sensed video file?

    I'm using a WVC80N camera and a WRT1900AC Wireless Router.  My HP MediaSmart server, WHS 2003, is connected to the router via cable.  I can have the camera ALWAYS RECORD to the server because the setup for that asks directly where to put the file.  H