Giter Club home page Giter Club logo

gridbagconstraintsbuilder's Introduction

GridBagConstraintsBuilder

A Builder for Swing GridBagConstraints to ease the creation of Gridbag-Layouts. Instead of having a long parameter list of the GridBagConstraints constructor the builder provides named methods.

Construct the builder with default values

	xPos = 0;
	yPos = 0;
	width = 1;
	height = 1;
	weightX = 0;
	weightY = 0;
	anchor = GridBagConstraints.WEST;
	fill = GridBagConstraints.NONE;
	insets = new Insets(0, 0, 0, 0);
	paddingX = 0;
	paddingY = 0;

or use constructor with Java GridBagContraintsBuilder(GridBagConstraints initialConfiguration) to set own default values for reset.

There are two approches to place the compontents on the grid:

1.) Explicit setting x and y pos:

	GridBagContraintsBuilder gbb = new GridBagContraintsBuilder();
	mainPanel.add(firstRowFirstCol, gbb.x(0).y(0).insets(5).buildAndReset());
	mainPanel.add(firstRowSecondCol, gbb.x(1).y(0).insets(5).rowRemainder().buildAndReset());
	mainPanel.add(secondRowFirstCol, gbb.x(0).y(1).insets(5).buildAndReset());

2.) Working column by column and row by row

	GridBagContraintsBuilder gbb = new GridBagContraintsBuilder();
	mainPanel.add(firstRowFirstCol, gbb.x(0).y(0).insets(5).build());
	mainPanel.add(firstRowSecondCol, gbb.newCol().insets(5).rowRemainder().build());
	mainPanel.add(secondRowFirstCol, gbb.newRow().insets(5).build());

Example:

	GridBagContraintsBuilder gbb = new GridBagContraintsBuilder();

	mainPanel.add(firstRowFirstCol, gbb.x(0).y(0).insets(5).buildAndReset());
	mainPanel.add(firstRowSecondCol, gbb.x(1).y(0).insets(5).rowRemainder().buildAndReset());

	mainPanel.add(secondRowFirstCol, gbb.x(0).y(1).insets(5).buildAndReset());
	mainPanel.add(secondRowSecondCol, gbb.x(1).y(1).insets(5).buildAndReset());
	mainPanel.add(secondRowThirdCol, gbb.x(2).y(1).insets(5).buildAndReset());

	mainPanel.add(thirdRowFirstCol, gbb.x(0).y(2).insets(5).buildAndReset());
	mainPanel.add(thirdRowSecondCol, gbb.x(1).y(2).insets(5).expandHorizontal().rowRemainder().buildAndReset());

	mainPanel.add(fourthRowFirstCol, gbb.x(0).y(3).insets(5).buildAndReset());
	mainPanel.add(fourthRowSecondCol, gbb.x(1).y(3).insets(5).south().buildAndReset());
	mainPanel.add(fourthRowThirdCol, gbb.x(2).y(3).insets(5).expandBoth().buildAndReset());

	mainPanel.add(fifthRowFirstCol, gbb.x(0).y(4).insets(5).buildAndReset());
	mainPanel.add(fifthRowSecondCol, gbb.x(1).y(4).insets(5).buildAndReset());
	mainPanel.add(fifthRowThirdCol, gbb.x(2).y(4).insets(5).east().buildAndReset());

Screenshot

gridbagconstraintsbuilder's People

Contributors

anleu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.