GridBagLayout to create a board

Hi all.
I am using a GridBagLayout to create a board of 11x11 squares. These squares will be buttons, and all will be of the same size. But it has to be like a board made of bricks. The first row will be formed by 11 buttons. The first square of the second row has to start in the middle of the first square of the first row. The third row will be as the first row, and the fourth row as the second row...
My intention has been to use a GridBagLayout where the grid were formed by 11x21 squares, and each square will use two cells of width. I was thinking of putting the first button on the (0,0), the second on the (2,0), (4,0) ... (20,0).The first button of the second row on the (1,1), the second button of the second row on the (1,3)... (1,21).
This is what I have used:
import gato.PanelGato;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class ButtonTest {
     private static PanelGato panel;
     public static void main (String[] args) {
          panel = new PanelGato();
          panel.setLayout(new GridBagLayout());
          JFrame frame = new JFrame ();
          createPanel();
          frame.setPreferredSize(new Dimension(800,800));
          frame.add(panel);
          frame.pack();
          frame.setVisible(true);
     public static void createPanel () {
          GridBagConstraints c = new GridBagConstraints();
          for (int i=0; i<11; i++) {
               int modOdd = 0;
               if (i%2==1)
                    modOdd = 1;          
               for (int j=0; j<11; j++) {
//The 11 squares of a row are created here. gridy = the number of row, gridx = twice the number of row (+ 1 if it is a even row)
//The gridwidth = 2 because I want the buttons to use two cells.
                    c = new GridBagConstraints();
                    c.gridy = i;
                    c.gridx = 2*j+modOdd;
                    c.gridwidth=2;//case B: c.gridwidth=1
                    panel.add(new JButton(),c);
}The result is a simple board, where the second row starts in the same place as the first row, and all the board is a square.
In the case B, where c.gridwidth=1, the result is like a chessboard where the buttons are only the black squares. It is not a "brick board", because the first button of the second row starts where the first one of the first row ends.
Could anyone help me?
Thank you very much for reading it :)

A column (or row) in a GridBagLayout is not well defined unless there is at least one component which occupies only that column (or row). All your rows have components spanning 2 columns.
For the "brick wall" layout you want, IMO the best way to do this is by adding a dummy row with weighty=0 so it doesn't occupy vertical space.public class BrickWall {
   private JPanel panel;
   GridBagConstraints gbc;
   public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
         @Override
         public void run() {
            new BrickWall().makeUI();
   public void makeUI() {
      panel = new JPanel(new GridBagLayout());
      gbc = new GridBagConstraints();
      gbc.fill = GridBagConstraints.BOTH;
      gbc.weightx = 0.1;
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.gridwidth = 2;
      gbc.weighty = 0.1;
      for (gbc.gridy = 0; gbc.gridy < 11; gbc.gridy++) {
         for (gbc.gridx = 0; gbc.gridx < 21; gbc.gridx += 2) {
            if (gbc.gridx == 0 && gbc.gridy % 2 == 1) {
               addFiller(); // not strictly necessary
               gbc.gridx++;
            panel.add(new Brick(), gbc);
         if (gbc.gridy % 2 == 1) {
            addFiller(); // necessary!
      gbc.weighty = 0.0;
      for (gbc.gridx = 0; gbc.gridx < 21; gbc.gridx++) {
         addFiller();
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(400, 400);
      frame.add(panel);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
   private void addFiller() {
      gbc.gridwidth = 1;
      panel.add(new JPanel(), gbc);
      gbc.gridwidth = 2;
   class Brick extends JPanel {
      Brick() {
         setBackground(Color.PINK);
         setBorder(BorderFactory.createLineBorder(Color.RED));
}Note: Next time, post compilable code. We don't have your PanelGato class to test your code.
db

Similar Messages

  • How to create dash board

    Hi All,
    Can any body explain how to create dash board step by step. actually i have been asked to create a dash board for inventory.
    Regards,
    Viren.

    Hi Viren,
    To create a web template you need to have the Web Application Dsigner (WAD) which is a part of the Bex Suite.
    In the WAD you have different web items, like table,  chart, drop down box etc. These an be used for designing the look and feel of the web application. But you need to supply them with data. This can be done by using a query or a view as a Data Provider.
    The WAD is quite simple to operate with mostly drag and drop functions for including the web items in your template.
    Also see this:
    http://help.sap.com/saphelp_nw04/helpdata/en/44/b26a3b74a4fc31e10000000a114084/content.htm
    Hope this helps...

  • Is there any way to create discussion board using JSP

    Hi! i'm doing a project using jsp is there any way to create a simple discussion board like the one here? can anyone who knows pls forward some links that teaches me how to do it step by step. Thanks for your help and have a nice day :)

    From the UK! -- PC Plus, August 2000 Issue:
    How to build a JSP Message Board
    http://www.pcplus.co.uk/media/pcplus/pdf/166/pcplus.166.progworld.java.pdf
    You'll get a nice 2-page pdf file, taken directly from the magazine
    --Dave                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Creating a board game

    I'm making a "board game" in Flash with Actionscript 3.0.
    When the player lands on a certain space, I want a window to pop up
    & they complete a word search game. The faster they complete
    the word search, the more points they would earn. I already have it
    working so that the word search swf pops up at the right time, but
    I'm not sure how to grab the time they completed the game in &
    send it back to the main movie. I got the word search code from
    here:
    http://www.subtangent.com/flash/
    and it's written in Actionsript 2.0. Is it still possible to use
    both together? If so, how can I send the time back to my main movie
    to figure out their score?
    Thanks,

    an as2 swf will work when loaded by an as3 swf. the two can
    communicate using the localconnection class.

  • Create key board shortcuts in RoboHelp

    Is it possible to create keyboard shortcuts in RoboHelp? Can
    they be assigned to styles?
    Is it possible to create macros that work within RoboHelp?
    And use shortcut keys to run them?:disgust;

    In that case you need to log your Feature Request at Please follow this link.
    http://www.Adobe.com/cfusion/mmform/index.cfm?name=wishform&product=38
    This link will take you to information about some free macro recorders.
    http://www.techsupportalert.com/best-free-hotkey-macro-recorder-utility.htm
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • Creating Flash Board Game (Multiplayer online)

    Hi,
    Right now i am doing on a project on Chinese Checkers which
    have 2 players, 3 players, 4 players, 6 players. I used SQL Server
    as database. game programmed in AS3, and i used web services to
    connect them. I used Timers to get data Consistently as Web
    services does not support data push like flash remoting. Due to
    budget issue, i have to use web service in my project for
    educational learning.
    I have created game lobby in flash, where user can chat, see
    whose online, and create or join game. One main question: Can i do
    all of them in frames without using external actionscript
    files?like coding in first frame.
    1st swf: Game Lobby --> press create button --> 2nd
    swf: Game Create Border -->3rd swf: Press 2 , 3 ,4 or 6 players
    button -> 4th swf: Game.

    an as2 swf will work when loaded by an as3 swf. the two can
    communicate using the localconnection class.

  • Creating Dash Board

    Hi
    We have a scenario were in we need to make daskboards, KPI trackers, even the BW report has to be there in the same iview.
    i have tried making use of layers but it always croses the 64k and throws an error.
    Suggest some method .we have a client reuiremnet.

    HI Rakesh
    You can make use of nested iviews
    and can see this <a href="https://www.sdn.sap.com/irj/sdn/wiki?path=/display/vc/tabstripswithnestediViews">https://www.sdn.sap.com/irj/sdn/wiki?path=/display/vc/tabstripswithnestediViews</a>
    This will help you out how to go about the problem.
    thanx
    Pankaj Prasoon

  • How to create board game in InDesign

    I
    am trying to create a board game in InDesign, similar to the trivial pursuit board game. In other words, an outer wheel that has been
    divided up in sectionsand then spoes to the center. I think I can figure out how to do the spoes and the center, but I am having problems doing the outer wheel.
    Any ideas? Should I be doing this in photoshop instead?
    Thanks,
    FG

    Pretty much the same thing in Illustrator or ID, but Illy has more sophisticated drawing tools, including things like polar coordinates and duplication that will allow you to drag a copy of one of the line segments around an arc, then repeat at the same angle.
    In any case, you want to make two concentric circles, then draw a series of radial line segments between them. I'd then select all and creat a compound path.

  • Video looks all "squished" and 16:9 creates boarder all around

    Hey,
    Thought I had this problem fixed. I am trying to export a clip I captured in FCP 5.1. I shot this footage in 24p Advanced with the DVX100. Well it looks squished and it creates a boarder all around instead of creating black bars at the top and bottom.
    In my video settings 16:9 anamorphic is checked. I had this problem fixed originally but it now has returned. Does anyone have any ideas?
    Chris

    Captain,
    Getting this problem in the canvas. The video looks widescreen there (the window to the right) and when I try to export via "Export with Quicktime Conversion" it exports it the way I described. Squished to 4:3 and creates a window boarder all around.
    My settings has Anamorphic checked so it should look 16:9. When I export it it looks all screwed up. Someone once told me a couple of days ago I needed to have it checked which I now do and everything worked great, now it doesn't. What gives?
    What else would I need to do?
    Chris

  • Did anybody ever try to create TNT/NAT based board and use for it NI drivers ?

    Hello
    I'm student and I'm really intrested if this is possible ? I saw few NI
    products based on TNT chip and this boards (cards) looks really simple. Did
    anybody know anything about any problem to do something like this ?
    Gorgo
    "Those who give up never win,
    and those who win never give up!", Luis Abreu

    Hello
    Thanks for answer. But you know this is a funy things. When I was reading
    documentation it's said that this chips have only T/L function, but when I
    was surfing thru internet I found on www.ni.com that it's can be used like a
    controler. It looked for my like mistake on web page so I wrote to National
    Instrument and they tell me - that this chips can also work like a
    controler. Where is the true ? After weeks or more I went to my university
    and I found in one computer GPIB ISA card developed by NI. The main chip was
    TNT4882 !
    Please correct me if I said something wrong !
    thanks for any help
    Gorgo
    ETI - Faculty of Measurment
    "There will always be those, who define
    the worth
    of their lives not by who they are
    but who they aren't.Not by what they are for
    but what hey are agains." J.F.Canady
    "Randy Solomonson" wrote in message
    news:[email protected]..
    > Hello-
    >
    > National Instruments sells the TNT4882TL chip, but this chip will only
    > function as a talker/listener. Integrating this chip onto a board
    > will create a board that does not have controller capabilities. The
    > NI driver will not work.
    >
    > Randy Solomonson
    > Application Engineer
    > National Instruments

  • How can I create Airport Departures Board using Motion 5 ?

    I'd like to create an Airport Departures Board using Motion 5. Can anybody give any advice please ?
    Tks

    mmm.... yeah....
    Got Motion 4? A couple of the LiveFonts in M4 or LiveType can create that effect easily, but all that is gone in Motion 5.
    In Motion 5, you have to basically fake it.
    I'd like to offer this approach as the easiest to implement.
    Add a Camera (switch project to 3D).
    Create a line of text. (In the inspector, Text > Format > Advanced Formatting, check All Caps and set All Caps size to 100%)
    Pick a Monospace font (Monaco, Courier, Andale, Menlo - or find and install one that looks more like you want.)
    To the line of text, add Behaviors > Text Energetic > Flip In (you can work on Flip out afterwards - same basic steps)
    To the Behavior, use the Parameter > Remove button to remove Face > Blur and Outline > Blur (or just set both to 0%)
    Twirl down the Rotation and set the X Rotation to -360 (instead of the default 360 - it's flipping the wrong direction for what you want)
    [Optional: Parameter > Add  >  Format > Character Offset -- set it to about 6 -- this will "randomize" the characters as they animate "in"]
    Set the playhead to about half way through the animation so you can see some flipping characters
    Go to the Text > Layout pane in the inspector
    Under Behavior Controls, Anchor Point - click on the Position disclosure triangle and adjust the Y value up until the flipping characters line up to the midpoint of the character.
    Play.
    With the Flip In behavior selected in the Layers list, adjust the end point to adjust the speed (optional).
    You can combine this with Flip Out and timing other text overlaid at the same location to create in/out transitions between texts (old text Flips Out while new text Flips In...).
    Build a background to create the "board" with outlines and shading. Line up the texts in space so that they just overlay the background graphic (use Position > Z parameter or set up the graphics to be just below the text in the layer list. In a 3D project, the letters will rotate "through" the solid background.)
    At this point, I'll have to leave the rest up to you.  You'll be going for an optical illusion basically. If it animates quickly enough, I doubt most people would notice the difference.
    HTH

  • Error while transporting Planning board profiles from Dev to QA

    Hi All,
    I have created planning board profile by copying an already existing Non-Standard profile.
    The Profile is working fine in Dev and i am able to see all the charts and Graphical objects as per the settings in the profile.
    But when i transport the profile to QA, it is giving error SAPBARC with text "Illegal number of columns in Chart". I checked what setting have been transported, and found that many of the setting have not been transported for the profile.
    Also tried to move all the profiles, thinking, there might be some dependcy among them. But the problem still persists.
    Awaiting for help...
    Thanks in advance..:).

    Hi Davis,
    Before transporting transformation make sure either of source or target should availble in target system.
    suppose you have a transformation between Data source and Data Target, first transport Data source, then transport Transformation along with data target.
    Before tansporting Transformation either source or target should be avaialble in QA system..then only transportation will happen smoothly..
    Hope this helps.
    regards
    SK

  • Sharepoint 2013 Discussion Board Web Part, Subject line link on Home Page does not link to the list view

    I am by no means a SharePoint developer, but I really wanted to customize the discussion board for my site - so I found this link: http://www.codeproject.com/Articles/733164/How-to-create-HelpDesk-on-SharePoint-Online
    I added the columns, like the article said, and then completed the section "Modification of the discussion board views".  I skipped the workflow stuff because while I think it would be useful I wanted to make sure I could get
    the actual customization of the discussion board to work first. 
    My Problem (Just to preface - I followed the above instructions, including disabling the Minimal Download Strategy):
    When I clicked into my discussion board list, I was able to get it to look and function as described for both the subject and flat views. However, when I click on the Subject, from the Discussion Board Web Part on my Home Page, it does not redirect into the
    Discussion Board List Flat View.  Instead, it tries to open the root folder from the Home Page while still using the subject view.  The outcome being an empty discussion board on the Home Page.
    So I decided to create a whole new discussion board to see if that one would work, when I inserted a new Discussion Board Web Part into the Home Page, newly created from the app menu, it used the same custom JS file(plumTickets), even though I never linked
    the discussion board to the JS file. Of course when I went into the newly created Discussion Board list it opened as it does OOTB.
    I am so close it having this work like I have been envisioning.  I just need users to be able to click on a discussion subject from the Home Page and be redirected to the list view of the parent folder (I think that is the correct terminology,
    but it may not be) so they would be able to see any replies and be able to reply.  Please Help Me!!!
    I truly appreciate any help you are able to provide, thank you!

    I figured it out. I was using ?FilterField1=fieldname&FilterValue1=value on the URL to the page to pick out one project number. The web part I was trying to add was for a list that did not have that particular fieldname. I didn't realize that would matter
    since I was using the Connections -> Get Filter Values From to get my filter values from the main web part, which does have that fieldname.
    I added a field with that fieldname to the other list and set a workflow to copy the lookup value of the project number lookup field into the new field. Now all is working fine.  Sorry for the wild geese in my original question.

  • How to create a via from layer 1 to 3 on a 8 layer PCB?

    I'm working on a design for a 8 layer PCB with Multisim/Ultiboard v10. In Multisim under sheet properties i selected the PCB to contain 8 layers, which makes Ultiboard to create this board with 4 layer pairs and 0 top/bottom build-ups. In the PCB properties of Ultiboard i enabled micro vias and buried/blind vias but i noticed that i'm not able to allow vias between some combinations of layers.
    For example i can enable vias from top to the second layer (1st inner) and from top to the fourth layer (3rd inner), but not from top to the third layer (2nd inner).
    When placing a via, i can select top for the start and the 3rd layer
    for the end, but it will be created as via between top and the 4th
    layer, which will -of course- shorten several traces on the 4th layer.
    So my questions is: Why am i not allowed to create a via, that goes from the top layer to the third layer and how to enable all possible combinations of start and ending layers for the via?
    Thanks for your help
    fhn
    PS: sorry for my bad english :/ 
    Message Edited by fhn on 08-22-2008 04:39 AM

    I am not 100% sure about this, but what I see happening here is that you can only select certain combinations of pairs. Once that selection is made it will gey out other selections as not valid. You might want to carefully look at the options in the via selection and make sure of which layers you want vias to be on. I don't know about enabling all layers in this selection. I would assume this would not be legal from a design rules standpoint, but since most of my boards are either single or double sided I do not have the necessary experience with multi-layers to give a proper answer to that.
    This is the only thing I can advise as when I went through the process I was able tio select the vias for the layers you outlined in your post.
    I hope this helps somewhat as this is all can tell you.
    Kittmaster's Component Database
    http://ni.kittmaster.com
    Have a Nice Day

  • I want to create a border...

    but it is not working!!!!!!! I want to create a border around a box. What I have done is create 2 separate transform groups one with the filled boxes and another with lines. The border works fine if it is just around one box in any position but when it is placed around a group of boxes it doesn't work! Consider the board a boardgame board... there have to be borders around the boxes so that the users can know where a square ends and begins spent all day on this today... didn't think that something so simple would be so difficult!! Thank you in advance for helping! Below is the code
    //This is the code for creating the squares
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.geometry.*;
    import com.sun.j3d.utils.image.TextureLoader;
    public class Square
         public static final float LENGTH = (float)0.05;
         public static final float DEPTH = (float)0.0125;
         public int column;
         public int row;
         public float x;
         public float y;
         public float z;
         private TransformGroup trans;
         private TransformGroup blackLines;
         private Box square;
         private Box lineSquare;
         private Group subGroup;
         private Group lineGroup;
         public Square(Texture boardpic, int column, int row)
              this.column = column;
              this.row = row;
              subGroup = new BranchGroup();
              lineGroup = new BranchGroup();
              Color3f grey = new Color3f(0.5f,0.5f,0.5f);
              Color3f black = new Color3f(1.0f,1.0f,1.0f);
         Transform3D t = new Transform3D( );
              float distanceToEdge = ( LENGTH * (float)4.0 ) - ( LENGTH / (float)2.0 );
              //System.out.println(distanceToEdge);
              trans= new TransformGroup();
              blackLines = new TransformGroup();
              x = -distanceToEdge + ( column * LENGTH ) ;
         y = distanceToEdge - ( row * LENGTH ) ;
              z = -DEPTH;
    Vector3f v = new Vector3f(x, y, z);
              t.setTranslation(v);
              trans.setTransform(t);
              trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
              trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
              blackLines.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
              blackLines.setTransform(t);
              //sets a black line around a square                    
              Appearance blackLineApp = new Appearance();
              blackLineApp.setColoringAttributes(new ColoringAttributes(black,ColoringAttributes.NICEST));
              PolygonAttributes blPolyAt=new PolygonAttributes(PolygonAttributes.POLYGON_LINE,
                                            PolygonAttributes.CULL_FRONT,0f);
              //blPolyAt.setPolygonOffset(100.0f);
              //blPolyAt.setPolygonOffsetFactor(100.0f);
              blackLineApp.setPolygonAttributes(blPolyAt);
              lineSquare = new Box((LENGTH / 2.0f), (LENGTH / 2.0f), DEPTH, blackLineApp);
              subGroup.addChild(lineSquare);
              //Attributes for creating the filled box
              Appearance appearance = new Appearance();
              PolygonAttributes polyAt=new PolygonAttributes(PolygonAttributes.POLYGON_FILL,
                                            PolygonAttributes.CULL_NONE,0f);
              polyAt.setPolygonOffset(0.1f);
              polyAt.setPolygonOffsetFactor(0.1f);
              appearance.setPolygonAttributes(polyAt);
              appearance.setColoringAttributes(new ColoringAttributes(grey,ColoringAttributes.NICEST));
              appearance.setTexture(boardpic);
              TextureAttributes texAttr = new TextureAttributes();
              texAttr.setTextureMode(TextureAttributes.MODULATE);
              appearance.setTextureAttributes(texAttr);     
              Box square = new com.sun.j3d.utils.geometry.Box((LENGTH / 2.0f), (LENGTH / 2.0f), DEPTH, appearance);
              trans.addChild(square);
              subGroup.addChild(trans);
              subGroup.addChild(blackLines);
         public Group getGroup()
              return subGroup;
         public Group getLines()
              return lineGroup;
    //this the code for creating the board
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.GraphicsConfiguration;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.geometry.*;
    import com.sun.j3d.utils.image.TextureLoader;
    public class Board extends JFrame
         public Square[][] fullBoard = new Square[23][23];
         public Board()
              GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
              Canvas3D c = new Canvas3D(config);
              BranchGroup bg = new BranchGroup();
              TextureLoader picload = new TextureLoader("brown001.gif", this);
              Texture texture = picload.getTexture();
              texture.setMagFilter(Texture.BASE_LEVEL_LINEAR | Texture.NICEST);
              texture.setMinFilter(Texture.BASE_LEVEL_LINEAR | Texture.NICEST);
              for(int col = 1; col < 23; col++)
                   for (int row = 1; row < 23; row++)
                        fullBoard[col][row]=new Square(texture, (col-11), (row-11));
                        bg.addChild(fullBoard[col][row].getGroup());
                        //bg.addChild(fullBoard[col][row].getLines());
              TransformGroup tg = new TransformGroup();
              tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
              Transform3D rotation = new Transform3D();
              rotation.rotX(java.lang.Math.toRadians( -45 ));
              tg.setTransform(rotation);
              tg.addChild(bg);
              BranchGroup scene = new BranchGroup();
              scene.addChild(tg);
              scene.compile();
              SimpleUniverse u = new SimpleUniverse();
              u.getViewingPlatform().setNominalViewingTransform();
              u.addBranchGraph(scene);
              System.out.println("I am here now");
         public static void main (String [] args)
              Board b = new Board();
    Thanks again...
    -JET-

    Sorry the line:
    subGroup.addChild(lineSquare);
    should read:
    blackLines.addChild(lineSquare);

Maybe you are looking for

  • Prerequisite check of database instance installation failed on Solaris

    Dear All, Please provide your valuable suggestions in resolving the below issue We are installing the SAP NW 7.4 EP as distributed installation Application server on RHEL 6 and Oracle database on Solaris 11(SPARC). We have installed the SCS instance

  • Problem with pgi for returns delivery

    Hi, I'm trying to do PGI for returns delivery through BAPI_GOODSMVT_CREATE. The when the delivery is opened through VL02N, the Post Goods Issue button has Post Goods Receipt text written on it. When the GI is done, the material document has movement

  • How do I get photos from out of the trash on my MacBook Pro

    How do I remove photos from the Trash on my MacBook Pro?  Am using Kodak Easyshare program and have tried using both to no avail Pat

  • Incorrect pass word

    I just bought this laptop and created a user account. When I am trying to log in back, the password is not acceptable. 1. How can I get into the system and start using the laptop. 2. Can I make a password free login.

  • Locking a central contact

    Hi SRM Gurus, I distribute a central contract to ECC, then lock it for some time. Wondering what error message will appear in ECC, if we try to create a PO with reference to the distributed contract. Please give your feedback also paste the link of t