├── www
├── articles
│ ├── TableLayoutTutorialPart2
│ │ ├── MakePagesJar.bat
│ │ ├── apps
│ │ │ ├── Example2.jar
│ │ │ ├── grid.jnlp
│ │ │ ├── multicell.jnlp
│ │ │ ├── toggle1.jnlp
│ │ │ ├── toggle2.jnlp
│ │ │ ├── borderSimple.jnlp
│ │ │ ├── bidi.jnlp
│ │ │ ├── scrolling1.jnlp
│ │ │ ├── scrolling2.jnlp
│ │ │ ├── borderLeftMenu.jnlp
│ │ │ ├── multicellJustify.jnlp
│ │ │ └── borderStatus.jnlp
│ │ ├── images
│ │ │ ├── Multicell.gif
│ │ │ ├── ExampleGrid.gif
│ │ │ ├── ExampleBorder1.gif
│ │ │ ├── ExampleBorder2.gif
│ │ │ ├── ExampleBorder3.gif
│ │ │ ├── ExampleToggle1.gif
│ │ │ ├── ExampleToggle2.gif
│ │ │ ├── LaunchExample.gif
│ │ │ ├── MulticellGrid.gif
│ │ │ └── TableLayout-Part2.gif
│ │ ├── pages
│ │ │ ├── example2
│ │ │ │ ├── Bidi.class
│ │ │ │ ├── Grid.class
│ │ │ │ ├── Multicell.class
│ │ │ │ ├── Toggle1.class
│ │ │ │ ├── Toggle2.class
│ │ │ │ ├── Scrolling1.class
│ │ │ │ ├── Scrolling2.class
│ │ │ │ ├── BorderLeftMenu.class
│ │ │ │ ├── BorderSimple.class
│ │ │ │ ├── BorderStatus.class
│ │ │ │ ├── MulticellJustify.class
│ │ │ │ ├── Scrolling2$Heading.class
│ │ │ │ ├── BorderStatus$Heading.class
│ │ │ │ ├── Scrolling2$StatusBar.class
│ │ │ │ ├── BorderLeftMenu$Heading.class
│ │ │ │ ├── BorderLeftMenu$StatusBar.class
│ │ │ │ └── BorderStatus$StatusBar.class
│ │ │ ├── itox_files
│ │ │ │ ├── info.gif
│ │ │ │ ├── emailMath.gif
│ │ │ │ ├── itoxGraph.gif
│ │ │ │ ├── itoxProof.gif
│ │ │ │ └── background.htm
│ │ │ ├── hypercube_files
│ │ │ │ ├── info.gif
│ │ │ │ ├── image01.gif
│ │ │ │ ├── image02.gif
│ │ │ │ ├── image03.gif
│ │ │ │ ├── image04.gif
│ │ │ │ ├── image05.gif
│ │ │ │ ├── image06.gif
│ │ │ │ ├── image07.gif
│ │ │ │ ├── image08.gif
│ │ │ │ ├── image09.gif
│ │ │ │ ├── image10.gif
│ │ │ │ ├── image11.gif
│ │ │ │ ├── image12.gif
│ │ │ │ ├── image13.gif
│ │ │ │ ├── image14.gif
│ │ │ │ ├── image15.gif
│ │ │ │ ├── image16.gif
│ │ │ │ └── image17.gif
│ │ │ ├── TableLayout_files
│ │ │ │ ├── info.gif
│ │ │ │ ├── Header.gif
│ │ │ │ ├── background.gif
│ │ │ │ └── EmailTableLayout.jpg
│ │ │ ├── feedback_files
│ │ │ │ ├── Header.gif
│ │ │ │ └── background.gif
│ │ │ ├── info
│ │ │ │ └── clearthought
│ │ │ │ │ └── layout
│ │ │ │ │ ├── TableLayout.class
│ │ │ │ │ ├── SingleFiledLayout.class
│ │ │ │ │ ├── TableLayout$Entry.class
│ │ │ │ │ ├── TableLayoutConstants.class
│ │ │ │ │ └── TableLayoutConstraints.class
│ │ │ ├── sample.html
│ │ │ ├── itox.html
│ │ │ └── hypercube.html
│ │ └── TableLayoutTutorialPart2.doc
│ ├── TableLayoutTutorialPart1
│ │ ├── apps
│ │ │ ├── Example1.jar
│ │ │ ├── simple.jnlp
│ │ │ ├── grid.jnlp
│ │ │ ├── preferred.jnlp
│ │ │ ├── typical.jnlp
│ │ │ ├── gridbag.jnlp
│ │ │ └── rad.jnlp
│ │ ├── images
│ │ │ ├── BlueBall.gif
│ │ │ ├── FrameGrid.gif
│ │ │ ├── Preferred.gif
│ │ │ ├── RadAfter.gif
│ │ │ ├── RadBefore.gif
│ │ │ ├── TypicalGui.gif
│ │ │ ├── LaunchExample.gif
│ │ │ ├── RadOnStartup.gif
│ │ │ ├── SimpleSnapshot.gif
│ │ │ ├── GridVersusTable.gif
│ │ │ ├── GridBagVersusTable1.gif
│ │ │ ├── GridBagVersusTable2.gif
│ │ │ ├── GridBagVersusTable3.gif
│ │ │ ├── SimpleLineDiagram.gif
│ │ │ └── TableLayout-Part1.gif
│ │ └── TableLayoutTutorialPart1.doc
│ └── JComboBoxFixed
│ │ └── JComboBoxFixed.html
├── images
│ ├── download.jpg
│ ├── history.jpg
│ ├── license.jpg
│ ├── petition.jpg
│ ├── discussion.jpg
│ ├── tableDancer.jpg
│ ├── tablelayout.gif
│ ├── testimonies.jpg
│ ├── JComboBoxFixed.jpg
│ ├── totallyGridbag.gif
│ └── tableDancerLarge.jpg
├── index.html
└── general
│ ├── history.html
│ └── testimonies.html
├── extensions
├── info
│ └── clearthought
│ │ └── layout
│ │ └── TableLayoutPersistenceDelegate.java
└── example
│ └── Persistent.java
├── .classpath
├── README.md
├── .project
├── .settings
└── org.eclipse.jdt.core.prefs
└── src
├── example
├── Simple.java
├── Launch.java
├── Preferred.java
├── GridVersusTable.java
├── TestAddition.java
├── GridBagVersusTable.java
├── TypicalGui.java
└── BidiTest.java
├── exampleSupport
├── BlankPanel.java
├── BufferedPanel.java
├── BufferedFrame.java
└── BlankLabel.java
├── example2
├── Multicell.java
├── Scrolling1.java
├── MulticellJustify.java
├── Grid.java
├── Toggle1.java
├── Bidi.java
├── BorderSimple.java
└── Toggle2.java
└── info
└── clearthought
└── layout
└── TableLayoutConstants.java
/www/articles/TableLayoutTutorialPart2/MakePagesJar.bat:
--------------------------------------------------------------------------------
1 | cd pages
2 | jar -cf ../pages.jar *
3 | cd ..
--------------------------------------------------------------------------------
/www/images/download.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/images/download.jpg
--------------------------------------------------------------------------------
/www/images/history.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/images/history.jpg
--------------------------------------------------------------------------------
/www/images/license.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/images/license.jpg
--------------------------------------------------------------------------------
/www/images/petition.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/images/petition.jpg
--------------------------------------------------------------------------------
/www/images/discussion.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/images/discussion.jpg
--------------------------------------------------------------------------------
/www/images/tableDancer.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/images/tableDancer.jpg
--------------------------------------------------------------------------------
/www/images/tablelayout.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/images/tablelayout.gif
--------------------------------------------------------------------------------
/www/images/testimonies.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/images/testimonies.jpg
--------------------------------------------------------------------------------
/www/images/JComboBoxFixed.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/images/JComboBoxFixed.jpg
--------------------------------------------------------------------------------
/www/images/totallyGridbag.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/images/totallyGridbag.gif
--------------------------------------------------------------------------------
/www/images/tableDancerLarge.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/images/tableDancerLarge.jpg
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/apps/Example1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/apps/Example1.jar
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/apps/Example2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/apps/Example2.jar
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/images/BlueBall.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/images/BlueBall.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/images/FrameGrid.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/images/FrameGrid.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/images/Preferred.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/images/Preferred.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/images/RadAfter.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/images/RadAfter.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/images/RadBefore.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/images/RadBefore.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/images/Multicell.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/images/Multicell.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/images/TypicalGui.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/images/TypicalGui.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/images/ExampleGrid.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/images/ExampleGrid.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/images/LaunchExample.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/images/LaunchExample.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/images/RadOnStartup.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/images/RadOnStartup.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/images/SimpleSnapshot.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/images/SimpleSnapshot.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/images/ExampleBorder1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/images/ExampleBorder1.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/images/ExampleBorder2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/images/ExampleBorder2.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/images/ExampleBorder3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/images/ExampleBorder3.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/images/ExampleToggle1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/images/ExampleToggle1.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/images/ExampleToggle2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/images/ExampleToggle2.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/images/LaunchExample.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/images/LaunchExample.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/images/MulticellGrid.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/images/MulticellGrid.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/Bidi.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/Bidi.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/Grid.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/Grid.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/itox_files/info.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/itox_files/info.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/images/GridVersusTable.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/images/GridVersusTable.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/TableLayoutTutorialPart1.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/TableLayoutTutorialPart1.doc
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/images/GridBagVersusTable1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/images/GridBagVersusTable1.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/images/GridBagVersusTable2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/images/GridBagVersusTable2.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/images/GridBagVersusTable3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/images/GridBagVersusTable3.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/images/SimpleLineDiagram.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/images/SimpleLineDiagram.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart1/images/TableLayout-Part1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart1/images/TableLayout-Part1.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/TableLayoutTutorialPart2.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/TableLayoutTutorialPart2.doc
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/images/TableLayout-Part2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/images/TableLayout-Part2.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/Multicell.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/Multicell.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/Toggle1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/Toggle1.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/Toggle2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/Toggle2.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/info.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/info.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/itox_files/emailMath.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/itox_files/emailMath.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/itox_files/itoxGraph.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/itox_files/itoxGraph.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/itox_files/itoxProof.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/itox_files/itoxProof.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/TableLayout_files/info.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/TableLayout_files/info.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/Scrolling1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/Scrolling1.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/Scrolling2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/Scrolling2.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/feedback_files/Header.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/feedback_files/Header.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/itox_files/background.htm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/itox_files/background.htm
--------------------------------------------------------------------------------
/extensions/info/clearthought/layout/TableLayoutPersistenceDelegate.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/extensions/info/clearthought/layout/TableLayoutPersistenceDelegate.java
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/TableLayout_files/Header.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/TableLayout_files/Header.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/BorderLeftMenu.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/BorderLeftMenu.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/BorderSimple.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/BorderSimple.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/BorderStatus.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/BorderStatus.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/feedback_files/background.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/feedback_files/background.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image01.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image01.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image02.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image02.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image03.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image03.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image04.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image04.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image05.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image05.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image06.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image06.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image07.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image07.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image08.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image08.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image09.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image09.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image10.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image10.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image11.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image11.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image12.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image12.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image13.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image13.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image14.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image14.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image15.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image15.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image16.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image16.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image17.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/hypercube_files/image17.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/MulticellJustify.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/MulticellJustify.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/TableLayout_files/background.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/TableLayout_files/background.gif
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/Scrolling2$Heading.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/Scrolling2$Heading.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/BorderStatus$Heading.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/BorderStatus$Heading.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/Scrolling2$StatusBar.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/Scrolling2$StatusBar.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/TableLayout_files/EmailTableLayout.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/TableLayout_files/EmailTableLayout.jpg
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/BorderLeftMenu$Heading.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/BorderLeftMenu$Heading.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/BorderLeftMenu$StatusBar.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/BorderLeftMenu$StatusBar.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/example2/BorderStatus$StatusBar.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/example2/BorderStatus$StatusBar.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/info/clearthought/layout/TableLayout.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/info/clearthought/layout/TableLayout.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/info/clearthought/layout/SingleFiledLayout.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/info/clearthought/layout/SingleFiledLayout.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/info/clearthought/layout/TableLayout$Entry.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/info/clearthought/layout/TableLayout$Entry.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/info/clearthought/layout/TableLayoutConstants.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/info/clearthought/layout/TableLayoutConstants.class
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/info/clearthought/layout/TableLayoutConstraints.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JFormDesigner/swing-tablelayout/HEAD/www/articles/TableLayoutTutorialPart2/pages/info/clearthought/layout/TableLayoutConstraints.class
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
Welcome to our website.
7 | 8 |Page underconstruction. Check back soon.
9 | 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TableLayout 2 | 3 | > This repo is a clone of the original SVN repo at https://java.net/projects/tablelayout/. 4 | > It is here for **archiving only** because the java.net forge will be discontinued soon. 5 | 6 | ## Links 7 | 8 | - http://www.clearthought.info/sun/products/jfc/tsc/articles/tablelayout/ 9 | 10 | ## License 11 | 12 | [The Clearthought Software License, Version 2.0](src/info/clearthought/layout/TableLayout.java) 13 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 |

Download this file as a MS Word document here.
10 | 11 | 12 |You can email the author, Daniel Barbalace, at the following address:
13 | 
16 | 20 |
21 | */ 22 | 23 | public class Launch extends Applet implements ActionListener 24 | { 25 | 26 | boolean start; 27 | private String className; 28 | private Button button; 29 | 30 | public void init () 31 | { 32 | setBackground (Color.white); 33 | className = getParameter("className"); 34 | start = true; 35 | 36 | button = new Button("Launch " + className); 37 | button.addActionListener (this); 38 | add (button); 39 | } 40 | 41 | public void actionPerformed (ActionEvent e) 42 | { 43 | try 44 | { 45 | if (start) 46 | { 47 | launch(); 48 | button.setLabel ("Close " + className); 49 | } 50 | else 51 | { 52 | dispose(); 53 | button.setLabel ("Launch " + className); 54 | } 55 | 56 | start = !start; 57 | } 58 | catch (Exception error) 59 | { 60 | error.printStackTrace(); 61 | } 62 | } 63 | 64 | public void launch () throws Exception 65 | { 66 | String paramList[] = {"[Ljava.lang.String;"}; 67 | Method method = Misc.getMethod(className, "main", paramList); 68 | 69 | Object parameter[] = {new String[0]}; 70 | method.invoke (null, parameter); 71 | } 72 | 73 | public void dispose () throws Exception 74 | { 75 | Frame frame[] = Frame.getFrames(); 76 | 77 | for (int i = 0; i < frame.length; i++) 78 | frame[i].dispose(); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/exampleSupport/BlankPanel.java: -------------------------------------------------------------------------------- 1 | package exampleSupport; 2 | 3 | 4 | 5 | import java.awt.*; 6 | import java.awt.event.*; 7 | 8 | 9 | 10 | /** 11 | * A BlankPanel is an invisible panel that can be used as a placeholder for 12 | * layout managers and as containers that do not have backgrounds. 13 | * 14 | * @author Daniel E. Barbalace 15 | */ 16 | 17 | public class BlankPanel extends Container 18 | implements java.awt.event.ComponentListener 19 | { 20 | 21 | 22 | 23 | private final static LayoutManager panelLayout = new FlowLayout(); 24 | 25 | 26 | 27 | /** 28 | * Constructs a BlankPanel with the default layout, FlowLayout. 29 | */ 30 | 31 | public BlankPanel () 32 | { 33 | // Call parent constructor 34 | super(); 35 | 36 | // Set default layout 37 | setLayout (panelLayout); 38 | 39 | // This class needs to be notified when it is resized so it can lay out its 40 | // components. Otherwise, layouts will lag one resize behind. 41 | addComponentListener (this); 42 | } 43 | 44 | 45 | 46 | //****************************************************************************** 47 | //** java.awt.event.ComponentListener methods *** 48 | //****************************************************************************** 49 | 50 | 51 | 52 | /** 53 | * Invoked when component has been resized. 54 | * 55 | *
Derived classes that override this method must call this method in 56 | * their version so that components are layed out properly.
57 | */ 58 | 59 | public void componentResized (ComponentEvent e) 60 | { 61 | // Tell the container class (parent) to layout components. Without this 62 | // line, the layout manager will lag one resize behind. 63 | if (e.getSource() == this) 64 | doLayout(); 65 | } 66 | 67 | 68 | 69 | /** 70 | *Invoked when component has been moved. 71 | */ 72 | 73 | public void componentMoved (ComponentEvent e) 74 | { 75 | } 76 | 77 | 78 | 79 | /** 80 | * Invoked when component has been shown. 81 | */ 82 | 83 | public void componentShown (ComponentEvent e) 84 | { 85 | } 86 | 87 | 88 | 89 | /** 90 | * Invoked when component has been hidden. 91 | */ 92 | 93 | public void componentHidden (ComponentEvent e) 94 | { 95 | } 96 | 97 | 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/example/Preferred.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | 4 | 5 | import java.awt.*; 6 | import javax.swing.*; 7 | import info.clearthought.layout.TableLayout; 8 | 9 | 10 | 11 | public class Preferred extends JFrame 12 | { 13 | 14 | 15 | 16 | public static void main (String args[]) 17 | { 18 | new Preferred(); 19 | } 20 | 21 | 22 | 23 | public Preferred () 24 | { 25 | super("The Power of Preferred Sizes"); 26 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 27 | Container pane = getContentPane(); 28 | 29 | // b - border 30 | // f - FILL 31 | // p - PREFERRED 32 | // vs - vertical space between labels and text fields 33 | // vg - vertical gap between form elements 34 | // hg - horizontal gap between form elements 35 | 36 | double b = 10; 37 | double f = TableLayout.FILL; 38 | double p = TableLayout.PREFERRED; 39 | double vs = 5; 40 | double vg = 10; 41 | double hg = 10; 42 | 43 | double size[][] = 44 | {{b, f, hg, p, hg, p, b}, 45 | {b, p, vs, p, vg, p, vs, p, vg, p, vs, p, vg, p, b}}; 46 | 47 | TableLayout layout = new TableLayout(size); 48 | pane.setLayout (layout); 49 | 50 | // Create all controls 51 | JLabel labelName = new JLabel("Name"); 52 | JLabel labelAddress = new JLabel("Address"); 53 | JLabel labelCity = new JLabel("City"); 54 | JLabel labelState = new JLabel("State"); 55 | JLabel labelZip = new JLabel("Zip"); 56 | 57 | JTextField textfieldName = new JTextField(10); 58 | JTextField textfieldAddress = new JTextField(20); 59 | JTextField textfieldCity = new JTextField(10); 60 | JTextField textfieldState = new JTextField(2); 61 | JTextField textfieldZip = new JTextField(5); 62 | 63 | JButton buttonOk = new JButton("OK"); 64 | JButton buttonCancel = new JButton("Cancel"); 65 | JPanel panelButton = new JPanel(); 66 | panelButton.add(buttonOk); 67 | panelButton.add(buttonCancel); 68 | 69 | // Add all controls 70 | pane.add(labelName, "1, 1, 5, 1"); 71 | pane.add(textfieldName, "1, 3, 5, 3"); 72 | pane.add(labelAddress, "1, 5, 5, 5"); 73 | pane.add(textfieldAddress, "1, 7, 5, 7"); 74 | pane.add(labelCity, "1, 9"); 75 | pane.add(textfieldCity, "1, 11"); 76 | pane.add(labelState, "3, 9"); 77 | pane.add(textfieldState, "3, 11"); 78 | pane.add(labelZip, "5, 9"); 79 | pane.add(textfieldZip, "5, 11"); 80 | pane.add(panelButton, "1, 13, 5, 13"); 81 | 82 | pack(); 83 | setResizable(false); 84 | setVisible(true); 85 | toFront(); 86 | } 87 | 88 | 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/example/GridVersusTable.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | 4 | 5 | import java.awt.*; 6 | import java.awt.event.*; 7 | import javax.swing.JButton; 8 | import info.clearthought.layout.TableLayout; 9 | 10 | 11 | 12 | public class GridVersusTable { 13 | 14 | 15 | 16 | protected static Frame showGridWindow () 17 | { 18 | // Create frame 19 | Frame frame = new Frame("GridLayout"); 20 | frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); 21 | frame.setLayout (new GridLayout(2, 0)); 22 | 23 | // Create and add buttons 24 | frame.add (new JButton("One")); 25 | frame.add (new JButton("Two")); 26 | frame.add (new JButton("Three")); 27 | frame.add (new JButton("Four")); 28 | 29 | // Show frame 30 | frame.pack(); 31 | frame.setLocation (0, 10); 32 | frame.setVisible(true); 33 | frame.toFront(); 34 | 35 | return frame; 36 | } 37 | 38 | 39 | 40 | protected static Frame showTableWindow () 41 | { 42 | // Create frame 43 | Frame frame = new Frame("TableLayout"); 44 | frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); 45 | 46 | // Set layout 47 | double f = TableLayout.FILL; 48 | double size[][] = {{f, f}, {f, f}}; 49 | frame.setLayout (new TableLayout(size)); 50 | 51 | // Create and add buttons 52 | frame.add (new JButton("One"), "0, 0"); 53 | frame.add (new JButton("Two"), "1, 0"); 54 | frame.add (new JButton("Three"), "0, 1"); 55 | frame.add (new JButton("Four"), "1, 1"); 56 | 57 | // Show frame 58 | frame.pack(); 59 | frame.setLocation (200, 10); 60 | frame.setVisible(true); 61 | frame.toFront(); 62 | 63 | return frame; 64 | } 65 | 66 | 67 | 68 | protected static Frame showTableWindow2 () 69 | { 70 | // Create frame 71 | Frame frame = new Frame("TableLayout"); 72 | frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); 73 | 74 | // Set layout 75 | double f = TableLayout.FILL; 76 | double size[][] = {{f, f}, {f, f}}; 77 | frame.setLayout (new TableLayout(size)); 78 | 79 | // Create and add buttons 80 | frame.add (new JButton("One"), "0, 0"); 81 | frame.add (new JButton("Two"), "1, 1"); 82 | 83 | // Show frame 84 | frame.pack(); 85 | frame.setLocation (400, 10); 86 | frame.setVisible(true); 87 | frame.toFront(); 88 | 89 | return frame; 90 | } 91 | 92 | 93 | 94 | public static void main (String args[]) 95 | { 96 | WindowListener listener = 97 | (new WindowAdapter() 98 | { 99 | public void windowClosing (WindowEvent e) 100 | { 101 | System.exit (0); 102 | } 103 | } 104 | ); 105 | 106 | Frame frame = showGridWindow(); 107 | frame.addWindowListener(listener); 108 | 109 | frame = showTableWindow(); 110 | frame.addWindowListener(listener); 111 | 112 | frame = showTableWindow2(); 113 | frame.addWindowListener(listener); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/example/TestAddition.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | 4 | 5 | import java.awt.*; 6 | import java.awt.event.*; 7 | import javax.swing.*; 8 | import info.clearthought.layout.TableLayout; 9 | 10 | 11 | 12 | public class TestAddition extends Frame implements ActionListener 13 | { 14 | 15 | 16 | 17 | private JCheckBox buttonToggle; 18 | private Component hello; 19 | private JCheckBox checkboxRelayout; 20 | private JCheckBox checkboxTableLayout; 21 | private TableLayout tableLayout; 22 | private FlowLayout flowLayout; 23 | 24 | 25 | 26 | public static void main (String args[]) 27 | { 28 | new TestAddition(); 29 | } 30 | 31 | 32 | 33 | public TestAddition () 34 | { 35 | // Create a frame 36 | super("Test Addition"); 37 | setBounds (100, 100, 500, 300); 38 | 39 | // Create a TableLayout for the frame 40 | double border = 10; 41 | double f = TableLayout.FILL; 42 | double p = TableLayout.PREFERRED; 43 | double size[][] = 44 | {{border, p, p, p, border}, 45 | {border, f, p, border}}; 46 | 47 | tableLayout = new TableLayout(size); 48 | tableLayout.setVGap(10); 49 | tableLayout.setHGap(20); 50 | flowLayout = new FlowLayout(); 51 | setLayout (tableLayout); 52 | 53 | // Create and add controls 54 | buttonToggle = new JCheckBox("Toggle"); 55 | add(buttonToggle, "1, 2"); 56 | buttonToggle.addActionListener(this); 57 | 58 | hello = new JButton("Hello"); 59 | checkboxRelayout = new JCheckBox("Relayout and repaint", true); 60 | add (checkboxRelayout, "2, 2"); 61 | checkboxTableLayout = new JCheckBox("Use TableLayout", true); 62 | add (checkboxTableLayout, "3, 2"); 63 | checkboxTableLayout.addActionListener(this); 64 | 65 | // Allow user to close the window to terminate the program 66 | addWindowListener 67 | (new WindowAdapter() 68 | { 69 | public void windowClosing (WindowEvent e) 70 | { 71 | System.exit (0); 72 | } 73 | } 74 | ); 75 | 76 | // Show frame 77 | setVisible(true); 78 | toFront(); 79 | } 80 | 81 | 82 | 83 | public void actionPerformed (ActionEvent e) 84 | { 85 | Object source = e.getSource(); 86 | 87 | if (source == buttonToggle) 88 | { 89 | Container parent = hello.getParent(); 90 | 91 | if (parent == null) 92 | add(hello, "1, 1, 3, 1"); 93 | else 94 | parent.remove(hello); 95 | 96 | if (checkboxRelayout.isSelected()) 97 | { 98 | doLayout(); 99 | repaint(); 100 | } 101 | } 102 | else if (source == checkboxTableLayout) 103 | { 104 | if (checkboxTableLayout.isSelected()) 105 | setLayout(tableLayout); 106 | else 107 | setLayout(flowLayout); 108 | 109 | doLayout(); 110 | repaint(); 111 | } 112 | } 113 | 114 | 115 | 116 | } -------------------------------------------------------------------------------- /src/exampleSupport/BufferedPanel.java: -------------------------------------------------------------------------------- 1 | package exampleSupport; 2 | 3 | 4 | 5 | import java.awt.*; 6 | import java.awt.event.*; 7 | 8 | 9 | 10 | /** 11 | * BufferedPanel is a doubled buffered BlankPanel. 12 | * 13 | * @author Daniel E. Barbalace 14 | */ 15 | 16 | public class BufferedPanel extends BlankPanel 17 | { 18 | 19 | 20 | 21 | /** Offscreen buffer used for double buffering */ 22 | private Image offscreen; 23 | 24 | /** Offscreen buffer's graphics content */ 25 | private Graphics h; 26 | 27 | /** Size of offscreen buffer */ 28 | private Dimension o; 29 | 30 | 31 | 32 | /** 33 | * Constructs the panel. 34 | * 35 | * @param title text to display in window title area 36 | */ 37 | 38 | public BufferedPanel () 39 | { 40 | // Call parent constructor 41 | super(); 42 | 43 | // Initialize o 44 | o = new Dimension(0, 0); 45 | } 46 | 47 | 48 | 49 | /** 50 | * Updates this component. This method only does one thing: callspaint
51 | * .
52 | *
53 | * @param g Graphics context
54 | */
55 |
56 | public void update (Graphics g)
57 | {
58 | paint (g);
59 | }
60 |
61 |
62 |
63 | /**
64 | * Renders this frame using double buffering.
65 | *
66 | * @param g graphics canvas
67 | */
68 |
69 | public void paint (Graphics g)
70 | {
71 | // Make sure offscreen buffer exists
72 | if (h == null)
73 | // Abort painting, there is no space on which to draw
74 | return;
75 |
76 | // Call parent's paint
77 | super.paint (h);
78 |
79 | // Render canvas
80 | g.drawImage (offscreen, 0, 0, null);
81 | }
82 |
83 |
84 |
85 | /**
86 | * Creates the offscreen buffer used for double buffering.
87 | */
88 |
89 | private void createOffscreenBuffer ()
90 | {
91 | // Get size of panel
92 | o = getSize();
93 |
94 | // Make sure both width and height are positive to avoid a non-fatal
95 | // exception when creating an image for double buffering
96 | if ((o.width <= 0) || (o.height <= 0))
97 | // Abort function, there is no space on which to draw
98 | return;
99 |
100 | // Remove previous background image
101 | if (offscreen != null)
102 | {
103 | // GC
104 | offscreen.flush();
105 | offscreen = null;
106 | System.gc();
107 | }
108 |
109 | // Create offscreen canvas
110 | offscreen = Misc.createImage(o.width, o.height);
111 | h = offscreen.getGraphics();
112 | }
113 |
114 |
115 |
116 | /**
117 | * Disposes of this panel and all the resources it uses.
118 | */
119 |
120 | public void dispose ()
121 | {
122 | // Dispose of offscreen canvas
123 | if (offscreen != null)
124 | offscreen.flush();
125 |
126 | // Null all references
127 | h = null;
128 | o = null;
129 | offscreen = null;
130 |
131 | // Garbage collection
132 | System.gc();
133 | }
134 |
135 |
136 |
137 | //******************************************************************************
138 | //** java.awt.event.ComponentListener methods ***
139 | //******************************************************************************
140 |
141 |
142 |
143 | /**
144 | * Invoked when component has been resized.
145 | *
146 | * Derived classes that override this method must call this method.
147 | */ 148 | 149 | public void componentResized (ComponentEvent e) 150 | { 151 | // Call parent method 152 | super.componentResized (e); 153 | 154 | // Make sure the offscreen buffer is as large as the panel 155 | Dimension d = getSize(); 156 | 157 | if ((d.width > o.width) || (d.height > o.height)) 158 | createOffscreenBuffer(); 159 | 160 | // Erase previous image on offscreen canvas 161 | int imageWidth = offscreen.getWidth(null); 162 | int imageHeight = offscreen.getWidth(null); 163 | 164 | h.setColor (Color.white); 165 | h.fillRect (d.width, 0, imageWidth - d.width, imageHeight); 166 | h.fillRect (0, d.height, d.width, imageHeight - d.height); 167 | } 168 | 169 | 170 | 171 | } 172 | -------------------------------------------------------------------------------- /src/example/GridBagVersusTable.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | 4 | 5 | import java.awt.*; 6 | import java.awt.event.*; 7 | import javax.swing.JButton; 8 | import info.clearthought.layout.TableLayout; 9 | 10 | 11 | 12 | public class GridBagVersusTable 13 | { 14 | 15 | 16 | 17 | protected static void makeButton 18 | (Frame frame, String name, GridBagLayout gridbag, GridBagConstraints c) 19 | { 20 | JButton button = new JButton(name); 21 | gridbag.setConstraints(button, c); 22 | frame.add(button); 23 | } 24 | 25 | 26 | 27 | protected static Frame showGridBagWindow () 28 | { 29 | // Create layout and contraints object 30 | GridBagLayout gridbag = new GridBagLayout(); 31 | GridBagConstraints c = new GridBagConstraints(); 32 | 33 | // Create frame 34 | Frame frame = new Frame("GridBagLayout"); 35 | frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); 36 | frame.setLayout (gridbag); 37 | 38 | // Create buttons, add buttons, and apply constraints 39 | c.fill = GridBagConstraints.BOTH; 40 | c.weightx = 1.0; 41 | makeButton (frame, "Button1", gridbag, c); 42 | makeButton (frame, "Button2", gridbag, c); 43 | makeButton (frame, "Button3", gridbag, c); 44 | 45 | c.gridwidth = GridBagConstraints.REMAINDER; //end of row 46 | makeButton (frame, "Button4", gridbag, c); 47 | 48 | c.weightx = 0.0; //reset to the default 49 | makeButton (frame, "Button5", gridbag, c); //another row 50 | 51 | c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row 52 | makeButton (frame, "Button6", gridbag, c); 53 | 54 | c.gridwidth = GridBagConstraints.REMAINDER; //end of row 55 | makeButton (frame, "Button7", gridbag, c); 56 | 57 | c.gridwidth = 1; //reset to the default 58 | c.gridheight = 2; 59 | c.weighty = 1.0; 60 | makeButton (frame, "Button8", gridbag, c); 61 | 62 | c.weighty = 0.0; //reset to the default 63 | c.gridwidth = GridBagConstraints.REMAINDER; //end of row 64 | c.gridheight = 1; //reset to the default 65 | makeButton (frame, "Button9", gridbag, c); 66 | makeButton (frame, "Button10", gridbag, c); 67 | 68 | // Show frame 69 | frame.pack(); 70 | frame.setLocation (0, 10); 71 | frame.setVisible(true); 72 | frame.toFront(); 73 | 74 | return frame; 75 | } 76 | 77 | 78 | 79 | protected static Frame showTableWindow () 80 | { 81 | // Create frame 82 | Frame frame = new Frame("TableLayout"); 83 | frame.setFont(new Font("Helvetica", Font.PLAIN, 14)); 84 | 85 | // Set layout 86 | double f = TableLayout.FILL; 87 | double p = TableLayout.PREFERRED; 88 | double size[][] = {{f, f, f, f}, {p, p, p, p, f}}; 89 | 90 | TableLayout layout = new TableLayout(size); 91 | frame.setLayout (layout); 92 | 93 | // Create buttons labeled Button1 to Button10 94 | int numButton = 10; 95 | JButton button[] = new JButton[numButton + 1]; 96 | 97 | for (int i = 1; i <= numButton; i++) 98 | button[i] = new JButton("Button" + i); 99 | 100 | // Add buttons 101 | frame.add (button[1], "0, 0"); 102 | frame.add (button[2], "1, 0"); 103 | frame.add (button[3], "2, 0"); 104 | frame.add (button[4], "3, 0"); 105 | frame.add (button[5], "0, 1, 3, 1"); 106 | frame.add (button[6], "0, 2, 2, 2"); 107 | frame.add (button[7], "3, 2, 3, 2"); 108 | frame.add (button[8], "0, 3, 0, 4"); 109 | frame.add (button[9], "1, 3, 3, 3"); 110 | frame.add (button[10], "1, 4, 3, 4"); 111 | 112 | // Show frame 113 | frame.pack(); 114 | frame.setLocation (400, 10); 115 | frame.setVisible(true); 116 | frame.toFront(); 117 | 118 | return frame; 119 | } 120 | 121 | 122 | 123 | public static void main (String args[]) 124 | { 125 | WindowListener listener = 126 | (new WindowAdapter() 127 | { 128 | public void windowClosing (WindowEvent e) 129 | { 130 | System.exit (0); 131 | } 132 | } 133 | ); 134 | 135 | Frame frame = showGridBagWindow(); 136 | frame.addWindowListener (listener); 137 | 138 | frame = showTableWindow(); 139 | frame.addWindowListener (listener); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/example/TypicalGui.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | 4 | 5 | import java.awt.*; 6 | import java.awt.event.*; 7 | import javax.swing.*; 8 | import info.clearthought.layout.TableLayout; 9 | 10 | 11 | 12 | public class TypicalGui extends JFrame 13 | { 14 | 15 | 16 | 17 | public static void main (String args[]) 18 | { 19 | new TypicalGui(); 20 | } 21 | 22 | 23 | 24 | public TypicalGui () 25 | { 26 | super ("A Typical GUI"); 27 | 28 | Container pane = getContentPane(); 29 | 30 | double b = 10; 31 | double f = TableLayout.FILL; 32 | double p = TableLayout.PREFERRED; 33 | double size[][] = {{b, f, 5, p, 5, p, b}, {p, b, f, 10, p, b}}; 34 | TableLayout layout = new TableLayout(size); 35 | pane.setLayout (layout); 36 | 37 | addMenu(pane); 38 | addCommandButtons(pane, layout); 39 | addColorBoxes(pane, layout); 40 | addTextArea(pane, layout); 41 | 42 | allowClosing(); 43 | setSize (640, 480); 44 | setVisible(true); 45 | toFront(); 46 | } 47 | 48 | 49 | 50 | public void addMenu (Container pane) 51 | { 52 | JMenuBar menuBar = new JMenuBar(); 53 | 54 | String menuText[] = {"File", "Edit", "View", "Help"}; 55 | String itemText[][] = 56 | {{"New", "Open", "Save", "Print", "Exit"}, 57 | {"Cut", "Copy", "Paste"}, 58 | {"Zoom in", "Zoom out"}, 59 | {"About", "Index", "Search"}}; 60 | 61 | for (int i = 0; i < menuText.length; i++) 62 | { 63 | JMenu menu = new JMenu(menuText[i]); 64 | menuBar.add (menu); 65 | 66 | for (int j = 0; j < itemText[i].length; j++) 67 | { 68 | JMenuItem item = new JMenuItem(itemText[i][j]); 69 | menu.add (item); 70 | } 71 | } 72 | 73 | pane.add (menuBar, "0, 0, 6, 0"); 74 | } 75 | 76 | 77 | 78 | public void addCommandButtons (Container pane, TableLayout layout) 79 | { 80 | JPanel buttonPanel = new JPanel(); 81 | pane.add (buttonPanel, "1, 4, 5, 4"); 82 | 83 | for (int i = 1; i <= 5; i++) 84 | { 85 | JButton button = new JButton("Button " + i); 86 | buttonPanel.add (button); 87 | } 88 | } 89 | 90 | 91 | 92 | public void addColorBoxes (Container pane, TableLayout layout) 93 | { 94 | Color color[][] = 95 | {{Color.white, Color.black}, 96 | {Color.green, Color.blue}, 97 | {Color.red, Color.yellow}, 98 | {Color.pink, Color.orange}, 99 | {Color.magenta, Color.cyan}}; 100 | 101 | for (int i = 0; i < color.length; i++) 102 | { 103 | // Add a row for spacing and a row for the color boxes 104 | layout.insertRow (2, TableLayout.PREFERRED); 105 | layout.insertRow (2, 5); 106 | 107 | // Add color boxes 108 | pane.add (new ColorBox(color[i][0]), "3, 3"); 109 | pane.add (new ColorBox(color[i][1]), "5, 3"); 110 | } 111 | 112 | // Remove the unnecessary leading space 113 | layout.deleteRow (2); 114 | } 115 | 116 | 117 | 118 | public void addTextArea (Container pane, TableLayout layout) 119 | { 120 | int numRow = layout.getRow().length; 121 | JTextPane textArea = new JTextPane(); 122 | pane.add (textArea, "1, 2, 1, " + (numRow - 4)); 123 | } 124 | 125 | 126 | 127 | public void allowClosing () 128 | { 129 | addWindowListener 130 | (new WindowAdapter() 131 | { 132 | public void windowClosing (WindowEvent e) 133 | { 134 | System.exit (0); 135 | } 136 | } 137 | ); 138 | } 139 | 140 | 141 | 142 | //************************************************************************** 143 | //*** Inner classes *** 144 | //************************************************************************** 145 | 146 | 147 | 148 | protected class ColorBox extends Component 149 | { 150 | protected Color color; 151 | 152 | protected ColorBox (Color color) 153 | { 154 | this.color = color; 155 | } 156 | 157 | public void update (Graphics g) 158 | { 159 | paint (g); 160 | } 161 | 162 | public void paint (Graphics g) 163 | { 164 | Dimension d = getSize(); 165 | g.setColor (Color.black); 166 | g.drawRect (0, 0, d.width - 1, d.height - 1); 167 | 168 | g.setColor (color); 169 | g.fillRect (1, 1, d.width - 1, d.height - 1); 170 | } 171 | 172 | public Dimension getPreferredSize () 173 | { 174 | return new Dimension(40, 20); 175 | } 176 | } 177 | 178 | 179 | 180 | } 181 | -------------------------------------------------------------------------------- /src/example/BidiTest.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | import java.io.*; 7 | import javax.swing.*; 8 | import info.clearthought.layout.TableLayout; 9 | 10 | 11 | 12 | /** 13 | * Test the bidirectional support of TableLayout. 14 | * 15 | * @version 1.0 Oct 28, 2003 16 | * @author Daniel E. Barbalace 17 | */ 18 | 19 | public class BidiTest extends JFrame implements ActionListener 20 | { 21 | 22 | 23 | private static final long serialVersionUID = 3616453405678186808L; 24 | 25 | 26 | 27 | private JCheckBox checkboxIsLtr; 28 | private JCheckBox checkboxIsHzn; 29 | private JCheckBox checkboxTableLayout; 30 | private TableLayout tableLayout; 31 | private FlowLayout flowLayout; 32 | 33 | 34 | 35 | /** 36 | * Runes the test 37 | * 38 | * @param args Command line arguments 39 | */ 40 | 41 | public static void main (String [] args) 42 | { 43 | new BidiTest(); 44 | } 45 | 46 | 47 | /** 48 | * Constructs the test GUI. 49 | */ 50 | 51 | public BidiTest () 52 | { 53 | super("Test BiDi Support"); 54 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 55 | 56 | flowLayout = new FlowLayout(); 57 | double [][] size = {{-1, -1, -1}, {-1}}; 58 | tableLayout = new TableLayout(size); 59 | Container container = getContentPane(); 60 | container.setLayout(tableLayout); 61 | 62 | checkboxIsLtr = new JCheckBox("Left to right", true); 63 | checkboxIsHzn = new JCheckBox("Horizontal", true); 64 | checkboxIsLtr.addActionListener(this); 65 | checkboxIsHzn.addActionListener(this); 66 | container.add(checkboxIsLtr, "0, 0, LD, C"); 67 | container.add(checkboxIsHzn, "1, 0, LD, C"); 68 | 69 | checkboxTableLayout = new JCheckBox("TableLayout", true); 70 | container.add(checkboxTableLayout, "2, 0"); 71 | checkboxTableLayout.addActionListener(this); 72 | 73 | int numButton = 3; 74 | 75 | for (int i = 0; i < numButton; i++) 76 | { 77 | JButton button = new JButton("Button " + i); 78 | tableLayout.insertColumn(i, -1); 79 | container.add(button, "" + i + ", 0"); 80 | } 81 | 82 | setBounds(100, 100, 640, 480); 83 | setVisible(true); 84 | toFront(); 85 | } 86 | 87 | 88 | 89 | /** 90 | * Invoked when an action is performed. 91 | */ 92 | 93 | public void actionPerformed (ActionEvent e) 94 | { 95 | Object source = e.getSource(); 96 | Container container = getContentPane(); 97 | 98 | if (source == checkboxTableLayout) 99 | { 100 | if (checkboxTableLayout.isSelected()) 101 | container.setLayout(tableLayout); 102 | else 103 | container.setLayout(flowLayout); 104 | 105 | container.doLayout(); 106 | } 107 | else if ((source == checkboxIsLtr) || (source == checkboxIsHzn)) 108 | { 109 | boolean ltr = checkboxIsLtr.isSelected(); 110 | boolean hzn = checkboxIsHzn.isSelected(); 111 | 112 | ComponentOrientation o = createComponentOrientation(ltr, hzn); 113 | applyComponentOrientation(o); 114 | container.doLayout(); 115 | repaint(); 116 | } 117 | } 118 | 119 | 120 | /** 121 | * Used to create ComponentOrientation objects. 122 | */ 123 | 124 | public ComponentOrientation createComponentOrientation 125 | (boolean ltr, boolean hzn) 126 | { 127 | try 128 | { 129 | int [] arrayInt = 130 | { 131 | 0xAC, 0xED, 0x00, 0x05, 0x73, 0x72, 0x00, 0x1D, 0x6A, 0x61, 132 | 0x76, 0x61, 0x2E, 0x61, 0x77, 0x74, 133 | 0x2E, 0x43, 0x6F, 0x6D, 0x70, 0x6F, 0x6E, 0x65, 0x6E, 0x74, 134 | 0x4F, 0x72, 0x69, 0x65, 0x6E, 0x74, 135 | 0x61, 0x74, 0x69, 0x6F, 0x6E, 0xC6, 0xEA, 0xA7, 0x45, 0xA1, 136 | 0x9C, 0x63, 0xCC, 0x02, 0x00, 0x01, 137 | 0x49, 0x00, 0x0B, 0x6F, 0x72, 0x69, 0x65, 0x6E, 0x74, 0x61, 138 | 0x74, 0x69, 0x6F, 0x6E, 0x78, 0x70, 139 | 0x00, 0x00, 0x00, 0x06 140 | }; 141 | 142 | int numByte = arrayInt.length; 143 | byte [] array = new byte[numByte]; 144 | 145 | for (int i = 0; i < numByte; i++) 146 | array[i] = (byte) arrayInt[i]; 147 | 148 | array[numByte - 1] = (byte) ((ltr ? 4 : 0) | (hzn ? 2 : 0)); 149 | 150 | ByteArrayInputStream sba = new ByteArrayInputStream(array); 151 | ObjectInputStream si = new ObjectInputStream(sba); 152 | ComponentOrientation o = (ComponentOrientation) si.readObject(); 153 | si.close(); 154 | return o; 155 | } 156 | catch (Exception e) 157 | { 158 | e.printStackTrace(); 159 | System.exit(1); 160 | } 161 | 162 | return null; 163 | } 164 | 165 | 166 | 167 | /** 168 | * Used to hack ComponentOrientation. 169 | */ 170 | 171 | public void serialize () 172 | { 173 | try 174 | { 175 | FileOutputStream fo = new FileOutputStream("ltr.ser"); 176 | ObjectOutputStream so = new ObjectOutputStream(fo); 177 | so.writeObject(ComponentOrientation.LEFT_TO_RIGHT); 178 | so.flush(); 179 | so.close(); 180 | 181 | fo = new FileOutputStream("rtl.ser"); 182 | so = new ObjectOutputStream(fo); 183 | so.writeObject(ComponentOrientation.RIGHT_TO_LEFT); 184 | so.flush(); 185 | so.close(); 186 | 187 | fo = new FileOutputStream("unk.ser"); 188 | so = new ObjectOutputStream(fo); 189 | so.writeObject(ComponentOrientation.UNKNOWN); 190 | so.flush(); 191 | so.close(); 192 | } 193 | catch (Exception e) 194 | { 195 | e.printStackTrace(); 196 | System.exit(1); 197 | } 198 | } 199 | 200 | 201 | 202 | } 203 | -------------------------------------------------------------------------------- /src/example2/Multicell.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * 4 | * The Clearthought Software License, Version 1.0 5 | * 6 | * Copyright (c) 2001 Daniel Barbalace. All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. The original software may not be altered. However, the classes 16 | * provided may be subclasses as long as the subclasses are not 17 | * packaged in the info.clearthought package or any subpackage of 18 | * info.clearthought. 19 | * 20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, AFFILATED BUSINESSES, 24 | * OR ANYONE ELSE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 27 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * ==================================================================== 33 | */ 34 | 35 | 36 | 37 | package example2; 38 | 39 | 40 | 41 | import java.awt.*; 42 | import javax.swing.*; 43 | import java.util.*; 44 | import info.clearthought.layout.TableLayout; 45 | 46 | 47 | 48 | /** 49 | * Example of components spanning cells. 50 | * 51 | * @author Daniel E. Barbalace 52 | * @version 1.0, June 14, 2005 53 | */ 54 | 55 | public class Multicell 56 | { 57 | 58 | 59 | 60 | /** 61 | * Runs the program. 62 | */ 63 | 64 | public static void main (String args[]) 65 | { 66 | // Create frame 67 | JFrame frame = new JFrame("Local Area Connection - Primary Properties"); 68 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 69 | 70 | // Items to display in list control 71 | Vector listElement = new Vector(); 72 | listElement.add("Client for Microsoft Networks"); 73 | listElement.add("File and Print Sharing for Microsoft Networks"); 74 | listElement.add("QoS Packet Scheduler"); 75 | listElement.add("Microsoft TCP/IP version 6"); 76 | listElement.add("Internet Protocol (TCP/IP"); 77 | 78 | // Create controls 79 | JLabel labelConnect = new JLabel("Connect using:"); 80 | JTextField textfieldConnect = new JTextField("Intel(R) PRO/100 VE Network Connection"); 81 | JButton buttonConfigure = new JButton("Configure..."); 82 | JLabel labelUse = new JLabel("This connection uses the following items:"); 83 | JList list = new JList(listElement); 84 | JScrollPane scrollPane = new JScrollPane(list); 85 | JButton buttonInstall = new JButton("Install"); 86 | JButton buttonUninstall = new JButton("Uninstall"); 87 | JButton buttonProperties = new JButton("Properties"); 88 | JCheckBox checkboxShowIcon = new JCheckBox("Show icon in notification area when connected"); 89 | JCheckBox checkboxNotify = new JCheckBox("Notify me when this connection has limited or no connectivity"); 90 | JButton buttonOK = new JButton("OK"); 91 | JButton buttonCancel = new JButton("Cancel"); 92 | 93 | // Create and set layout 94 | double p = TableLayout.PREFERRED; 95 | double border = 10; 96 | double emptySpace = 10; 97 | double [] columnSize = {border, 1.0 / 3.0, TableLayout.FILL, 1.0 / 3.0, border}; 98 | double [] rowSize = {border, border}; 99 | TableLayout layout = new TableLayout(columnSize, rowSize); 100 | layout.setVGap(2); 101 | layout.setHGap(5); 102 | Container container = frame.getContentPane(); 103 | container.setLayout(layout); 104 | 105 | // Add controls 106 | layout.insertRow(1, p); 107 | container.add(labelConnect, "1, 1, 3, 1"); 108 | layout.insertRow(2, p); 109 | container.add(textfieldConnect, "1, 2, 2, 2"); 110 | container.add(buttonConfigure, "3, 2"); 111 | layout.insertRow(3, emptySpace); 112 | layout.insertRow(4, p); 113 | container.add(labelUse, "1, 4, 3, 4"); 114 | layout.insertRow(5, TableLayout.FILL); 115 | container.add(scrollPane, "1, 5, 3, 5"); 116 | layout.insertRow(6, p); 117 | container.add(buttonInstall, "1, 6"); 118 | container.add(buttonUninstall, "2, 6"); 119 | container.add(buttonProperties, "3, 6"); 120 | layout.insertRow(7, emptySpace); 121 | layout.insertRow(8, p); 122 | container.add(checkboxShowIcon, "1, 8, 3, 8"); 123 | layout.insertRow(9, p); 124 | container.add(checkboxNotify, "1, 9, 3, 9"); 125 | layout.insertRow(10, emptySpace); 126 | layout.insertRow(11, p); 127 | container.add(buttonOK, "2, 11"); 128 | container.add(buttonCancel, "3, 11"); 129 | 130 | // Show frame 131 | frame.pack(); 132 | frame.setVisible(true); 133 | frame.toFront(); 134 | } 135 | 136 | 137 | 138 | } 139 | -------------------------------------------------------------------------------- /src/example2/Scrolling1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * 4 | * The Clearthought Software License, Version 1.0 5 | * 6 | * Copyright (c) 2001 Daniel Barbalace. All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. The original software may not be altered. However, the classes 16 | * provided may be subclasses as long as the subclasses are not 17 | * packaged in the info.clearthought package or any subpackage of 18 | * info.clearthought. 19 | * 20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, AFFILATED BUSINESSES, 24 | * OR ANYONE ELSE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 27 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * ==================================================================== 33 | */ 34 | 35 | 36 | 37 | package example2; 38 | 39 | 40 | 41 | import java.awt.*; 42 | import javax.swing.*; 43 | import info.clearthought.layout.TableLayout; 44 | 45 | 46 | 47 | /** 48 | * Example of components spanning cells. 49 | * 50 | * @author Daniel E. Barbalace 51 | * @version 1.0, June 21, 2005 52 | */ 53 | 54 | public class Scrolling1 implements Runnable 55 | { 56 | 57 | 58 | 59 | /** Delay between updates in milliseconds */ 60 | private static final int DELAY = 1000 / 60; 61 | 62 | /** Space devoted to left/right bouncing */ 63 | private static final int BOUNCE_SPACE = 200; 64 | 65 | /** Half of the above space */ 66 | private static final int BOUNCE_SPACE_2 = BOUNCE_SPACE / 2; 67 | 68 | /** Instance of TableLayout we are using */ 69 | private TableLayout layout; 70 | 71 | /** Container being laid out */ 72 | private Container container; 73 | 74 | /** Thread used to scroll top button */ 75 | private Thread threadTop; 76 | 77 | /** Thread used to scroll bottom buttom */ 78 | private Thread threadBottom; 79 | 80 | 81 | 82 | /** 83 | * Runs the program. 84 | */ 85 | 86 | public static void main (String args[]) 87 | { 88 | new Scrolling1(); 89 | } 90 | 91 | 92 | 93 | /** 94 | * Creates the app. 95 | */ 96 | 97 | public Scrolling1() 98 | { 99 | // Create frame 100 | JFrame frame = new JFrame("Example of scrolling components"); 101 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 102 | frame.setResizable(false); 103 | 104 | // Create controls 105 | JButton buttonTop = new JButton("Scrolling"); 106 | JButton buttonBottom = new JButton("By your command"); 107 | 108 | // Create and set layout 109 | double f = TableLayout.FILL; 110 | double p = TableLayout.PREFERRED; 111 | double [] columnSize = {0, p, BOUNCE_SPACE}; 112 | double [] rowSize = {0, f, p}; 113 | layout = new TableLayout(columnSize, rowSize); 114 | container = frame.getContentPane(); 115 | container.setLayout(layout); 116 | 117 | // Add controls 118 | container.add(buttonTop, "0, 0, 2, 0"); 119 | container.add(buttonBottom, "1, 2"); 120 | 121 | // Show frame 122 | Dimension d = frame.getPreferredSize(); 123 | frame.setSize(d.width, 200); 124 | frame.setVisible(true); 125 | frame.toFront(); 126 | 127 | // Start the scrolling effects 128 | threadTop = new Thread(this); 129 | threadBottom = new Thread(this); 130 | threadTop.start(); 131 | threadBottom.start(); 132 | } 133 | 134 | 135 | 136 | /** 137 | * Routes threads. 138 | */ 139 | 140 | public void run() 141 | { 142 | Thread thread = Thread.currentThread(); 143 | 144 | if (thread == threadTop) 145 | runTop(); 146 | else if (thread == threadBottom) 147 | runBottom(); 148 | } 149 | 150 | 151 | 152 | /** 153 | * Scrolls the top button into and out of existence. 154 | */ 155 | 156 | private void runTop() 157 | { 158 | double size = 0; 159 | double delta = 1; 160 | 161 | while (true) 162 | { 163 | size += delta; 164 | layout.setRow(0, size); 165 | container.invalidate(); 166 | container.validate(); 167 | 168 | if (size == 0) 169 | delta = 1; 170 | else if (size == 50) 171 | delta = -1; 172 | 173 | try {Thread.sleep(DELAY);} catch (InterruptedException e) {} 174 | } 175 | } 176 | 177 | 178 | 179 | /** 180 | * Scrolls the bottom button left and right. 181 | */ 182 | 183 | private void runBottom() 184 | { 185 | int counter = 0; 186 | 187 | while (true) 188 | { 189 | int offset = BOUNCE_SPACE_2 + (int) 190 | (BOUNCE_SPACE_2 * Math.sin(0.01 * Math.PI * counter++)); 191 | 192 | layout.setColumn(0, offset); 193 | layout.setColumn(2, BOUNCE_SPACE - offset); 194 | container.invalidate(); 195 | container.validate(); 196 | 197 | try {Thread.sleep(DELAY);} catch (InterruptedException e) {} 198 | } 199 | } 200 | 201 | 202 | 203 | } 204 | -------------------------------------------------------------------------------- /www/articles/JComboBoxFixed/JComboBoxFixed.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |License
12 |13 | There is none. So don't even ask! This is public domain, no restrictions at all. Use it however you want. 14 |
15 | 16 |Legal Disclaimer
17 |18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 19 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, AFFILATED BUSINESSES, 22 | OR ANYONE ELSE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 25 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 28 | OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | SUCH DAMAGE. 30 |
31 |English Translation: Running this code might turn you into a werewolf. On the bright side, cool fangs!
32 |How to use this class
35 |
36 | Where you were doing a JComboBox combo = new JComboBox(...); instead do
37 | JComboBoxFixed combo = new JComboBoxFixed(...);.
38 |
Source code for JComboBoxFixed.java
41 |
42 | import java.awt.event.KeyEvent;
43 | import java.lang.reflect.Field;
44 |
45 | import javax.swing.JComboBox;
46 |
47 |
48 |
49 | /**
50 | * A class that fixes the bug described in the Java bug database as bug 4199622. See
51 | * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4199622.
52 | *
53 | * Note that as this workaround uses some aspects of reflection, it will require elevated rights in WebStart, applets, and other
54 | * restricted Java runtimes.
55 | *
56 | * @author Daniel E. Barbalace
57 | */
58 |
59 | public class JComboBoxFixed extends JComboBox
60 | {
61 | /** Used to prevent duplicate ActionEvents if the user presses [ENTER] on the item already selected. */
62 | private Object lastSelectedObject = null;
63 |
64 |
65 |
66 | /**
67 | * Overrides the JComboBox.processKeyEvent to alter the behavior of the [ENTER] key. This implementation allows the
68 | * [ENTER] key to generate ActionEvents in place of the ones filtered by the overridden "setSelectedItem" method.
69 | */
70 |
71 | public void processKeyEvent (KeyEvent e)
72 | {
73 | boolean shouldFireActionEvent = false;
74 |
75 | if (e.getKeyCode() == KeyEvent.VK_ENTER && (e.getID() & KeyEvent.KEY_PRESSED) == KeyEvent.KEY_PRESSED)
76 | {
77 | Object currentlySelectedObject = getSelectedItem();
78 |
79 | if (currentlySelectedObject != null && currentlySelectedObject != lastSelectedObject)
80 | shouldFireActionEvent = true;
81 |
82 | lastSelectedObject = currentlySelectedObject;
83 | }
84 |
85 | super.processKeyEvent(e);
86 |
87 | if (shouldFireActionEvent)
88 | fireActionEvent();
89 | }
90 |
91 |
92 |
93 | /**
94 | * Overrides the JComboBox.setSelectedItem to filter out the unwanted ActionEvents resulting from navigation of a JComboBox
95 | * using the arrow and paging keys.
96 | */
97 |
98 | public void setSelectedItem (Object anObject)
99 | {
100 | boolean shouldFireActionEvent = true;
101 | StackTraceElement [] listSte = Thread.currentThread().getStackTrace();
102 |
103 | for (StackTraceElement ste : listSte)
104 | {
105 | String methodName = ste.getMethodName();
106 |
107 | if ("processKeyBinding".equals(methodName))
108 | {
109 | shouldFireActionEvent = false;
110 | break;
111 | }
112 | else if ("mouseReleased".equals(methodName))
113 | {
114 | shouldFireActionEvent = true;
115 | break;
116 | }
117 | }
118 |
119 | if (shouldFireActionEvent)
120 | {
121 | super.setSelectedItem(anObject);
122 | }
123 | else
124 | {
125 | setFiringActionEvent(true);
126 | super.setSelectedItem(anObject);
127 | setFiringActionEvent(false);
128 | }
129 |
130 | }
131 |
132 |
133 |
134 | /**
135 | * Sets the value of the private field JComboBox.firingActionEvent.
136 | *
137 | * This method demonstrates the dark side of the force. You should never do what I'm doing in this method unless absolutely
138 | * necessary. I am only doing this because it is the least intrusive way of altering JComboBox to filter the unwanted
139 | * ActionEvents.
140 | *
141 | * @param value
142 | * Value to which to set the "firingActionEvent" field.
143 | */
144 |
145 | private void setFiringActionEvent (boolean value)
146 | {
147 | try
148 | {
149 | Class extends Object> c = this.getClass().getSuperclass();
150 | Field field = c.getDeclaredField("firingActionEvent");
151 | field.setAccessible(true);
152 | field.set(this, value);
153 | field.setAccessible(false);
154 | }
155 | catch (NoSuchFieldException ex)
156 | {
157 | ex.printStackTrace();
158 | }
159 | catch (IllegalAccessException ex)
160 | {
161 | ex.printStackTrace();
162 | }
163 | }
164 | }
165 |
166 |
167 |
168 |
--------------------------------------------------------------------------------
/src/example2/MulticellJustify.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ====================================================================
3 | *
4 | * The Clearthought Software License, Version 1.0
5 | *
6 | * Copyright (c) 2001 Daniel Barbalace. All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * 2. The original software may not be altered. However, the classes
16 | * provided may be subclasses as long as the subclasses are not
17 | * packaged in the info.clearthought package or any subpackage of
18 | * info.clearthought.
19 | *
20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, AFFILATED BUSINESSES,
24 | * OR ANYONE ELSE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 | * SUCH DAMAGE.
32 | * ====================================================================
33 | */
34 |
35 |
36 |
37 | package example2;
38 |
39 |
40 |
41 | import java.awt.*;
42 | import javax.swing.*;
43 | import java.util.*;
44 | import info.clearthought.layout.TableLayout;
45 |
46 |
47 |
48 | /**
49 | * Example of components spanning cells and using justification.
50 | *
51 | * @author Daniel E. Barbalace
52 | * @version 1.0, June 14, 2005
53 | */
54 |
55 | public class MulticellJustify
56 | {
57 |
58 |
59 |
60 | /**
61 | * Runs the program.
62 | */
63 |
64 | public static void main (String args[])
65 | {
66 | // Create frame
67 | JFrame frame = new JFrame("Local Area Connection - Primary Properties");
68 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
69 |
70 | // Items to display in list control
71 | Vector listElement = new Vector();
72 | listElement.add("Client for Microsoft Networks");
73 | listElement.add("File and Print Sharing for Microsoft Networks");
74 | listElement.add("QoS Packet Scheduler");
75 | listElement.add("Microsoft TCP/IP version 6");
76 | listElement.add("Internet Protocol (TCP/IP");
77 |
78 | // Create controls
79 | JLabel labelConnect = new JLabel("Connect using:");
80 | JTextField textfieldConnect = new JTextField("Intel(R) PRO/100 VE Network Connection");
81 | JButton buttonConfigure = new JButton("Configure...");
82 | JLabel labelUse = new JLabel("This connection uses the following items:");
83 | JList list = new JList(listElement);
84 | JScrollPane scrollPane = new JScrollPane(list);
85 | JButton buttonInstall = new JButton("Install");
86 | JButton buttonUninstall = new JButton("Uninstall");
87 | JButton buttonProperties = new JButton("Properties");
88 | JCheckBox checkboxShowIcon = new JCheckBox("Show icon in notification area when connected");
89 | JCheckBox checkboxNotify = new JCheckBox("Notify me when this connection has limited or no connectivity");
90 | JButton buttonOK = new JButton("OK");
91 | JButton buttonCancel = new JButton("Cancel");
92 |
93 | // Give buttons a definitive preferred size independent of their labels
94 | Dimension preferredSize = new Dimension(123, 26);
95 | buttonConfigure.setPreferredSize(preferredSize);
96 | buttonInstall.setPreferredSize(preferredSize);
97 | buttonUninstall.setPreferredSize(preferredSize);
98 | buttonProperties.setPreferredSize(preferredSize);
99 | buttonOK.setPreferredSize(preferredSize);
100 | buttonCancel.setPreferredSize(preferredSize);
101 |
102 | // Create and set layout
103 | double p = TableLayout.PREFERRED;
104 | double border = 10;
105 | double emptySpace = 10;
106 | double [] columnSize = {border, 1.0 / 3.0, TableLayout.FILL, 1.0 / 3.0, border};
107 | double [] rowSize = {border, border};
108 | TableLayout layout = new TableLayout(columnSize, rowSize);
109 | layout.setVGap(2);
110 | layout.setHGap(5);
111 | Container container = frame.getContentPane();
112 | container.setLayout(layout);
113 |
114 | // Place OK and cancel buttons in a panel so that they can be laid out
115 | // independently of all other controls
116 | JPanel panelButton = new JPanel();
117 | TableLayout layoutPanel = new TableLayout(new double [][] {{p, p}, {p}});
118 | layoutPanel.setHGap(5);
119 | panelButton.setLayout(layoutPanel);
120 | panelButton.add(buttonOK, "0, 0");
121 | panelButton.add(buttonCancel, "1, 0");
122 |
123 | // Add controls
124 | layout.insertRow(1, p);
125 | container.add(labelConnect, "1, 1, 3, 1");
126 | layout.insertRow(2, p);
127 | container.add(textfieldConnect, "1, 2, 2, 2");
128 | container.add(buttonConfigure, "3, 2");
129 | layout.insertRow(3, emptySpace);
130 | layout.insertRow(4, p);
131 | container.add(labelUse, "1, 4, 3, 4");
132 | layout.insertRow(5, TableLayout.FILL);
133 | container.add(scrollPane, "1, 5, 3, 5");
134 | layout.insertRow(6, p);
135 | container.add(buttonInstall, "1, 6, LEFT, TOP");
136 | container.add(buttonUninstall, "2, 6, CENTER, TOP");
137 | container.add(buttonProperties, "3, 6, RIGHT, TOP");
138 | layout.insertRow(7, emptySpace);
139 | layout.insertRow(8, p);
140 | container.add(checkboxShowIcon, "1, 8, 3, 8");
141 | layout.insertRow(9, p);
142 | container.add(checkboxNotify, "1, 9, 3, 9");
143 | layout.insertRow(10, emptySpace);
144 | layout.insertRow(11, p);
145 | container.add(panelButton, "1, 11, 3, 11, RIGHT, TOP");
146 |
147 | // Show frame
148 | frame.pack();
149 | frame.setVisible(true);
150 | frame.toFront();
151 | }
152 |
153 |
154 |
155 | }
156 |
--------------------------------------------------------------------------------
/src/example2/Grid.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ====================================================================
3 | *
4 | * The Clearthought Software License, Version 1.0
5 | *
6 | * Copyright (c) 2001 Daniel Barbalace. All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * 2. The original software may not be altered. However, the classes
16 | * provided may be subclasses as long as the subclasses are not
17 | * packaged in the info.clearthought package or any subpackage of
18 | * info.clearthought.
19 | *
20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, AFFILATED BUSINESSES,
24 | * OR ANYONE ELSE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 | * SUCH DAMAGE.
32 | * ====================================================================
33 | */
34 |
35 |
36 |
37 | package example2;
38 |
39 |
40 |
41 | import java.awt.*;
42 | import java.lang.reflect.*;
43 | import javax.swing.*;
44 | import info.clearthought.layout.*;
45 |
46 |
47 |
48 | /**
49 | * This class can show a grid on top of any container that uses TableLayout.
50 | *
51 | * @author Daniel E. Barbalace
52 | * @version 1.0, Jun 14, 2005
53 | */
54 |
55 | public final class Grid extends Component
56 | {
57 |
58 |
59 |
60 | private static Color gridColor = Color.BLACK;
61 | private static Color fillColor = null;
62 |
63 |
64 |
65 | /**
66 | * Runs the program.
67 | */
68 |
69 | public static void main (String args[])
70 | {
71 | setFillColor(Color.BLUE);
72 | String className = "example2.MulticellJustify";
73 |
74 | if (args.length == 1)
75 | className = args[0];
76 |
77 | try
78 | {
79 | Class cls = Class.forName(className);
80 | Class [] parameterType = {args.getClass()};
81 | Object [] parameter = {new String[0]};
82 | Method method = cls.getMethod("main", parameterType);
83 | method.invoke(null, parameter);
84 |
85 | Frame [] frame = Frame.getFrames();
86 |
87 | if (frame.length == 1)
88 | {
89 | if (frame[0] instanceof JFrame)
90 | showGrid(((JFrame) frame[0]).getContentPane());
91 | else
92 | showGrid(frame[0]);
93 | }
94 | }
95 | catch (Exception e)
96 | {
97 | e.printStackTrace();
98 | }
99 | }
100 |
101 |
102 |
103 | /**
104 | * Shows a grid on a given container provided that the container uses
105 | * TableLayout.
106 | *
107 | * @param container container using TableLayout. May not be null.
108 | */
109 |
110 | public static void showGrid (Container container)
111 | {
112 | if (container == null)
113 | throw new IllegalArgumentException("Parameter container cannot be null");
114 |
115 | LayoutManager l = container.getLayout();
116 |
117 | if (!(l instanceof TableLayout))
118 | throw new IllegalArgumentException("Container is not using TableLayout");
119 |
120 | TableLayout layout = (TableLayout) l;
121 |
122 | showGrid(container, layout);
123 |
124 | container.invalidate();
125 | container.validate();
126 | container.repaint();
127 | }
128 |
129 |
130 |
131 | /**
132 | * Shows a grid on a given container provided that the container uses
133 | * TableLayout.
134 | *
135 | * @param container container using TableLayout. May not be null.
136 | * @param layout TableLayout instance used by container. May not be null.
137 | */
138 |
139 | private static void showGrid (Container container, TableLayout layout)
140 | {
141 | int numRow = layout.getNumRow();
142 | int numCol = layout.getNumColumn();
143 |
144 | for (int y = 0; y < numRow; y++)
145 | for (int x = 0; x < numCol; x++)
146 | {
147 | Grid g = new Grid();
148 | container.add(g, new TableLayoutConstraints(x, y), 0);
149 | }
150 | }
151 |
152 |
153 |
154 | /**
155 | * Gets the grid color.
156 | *
157 | * @return the grid color
158 | */
159 |
160 | public static Color getGridColor()
161 | {
162 | return gridColor;
163 | }
164 |
165 |
166 |
167 | /**
168 | * Sets the grid color.
169 | *
170 | * @param color new grid color
171 | */
172 |
173 | public static void setGridColor (Color color)
174 | {
175 | gridColor = color;
176 | }
177 |
178 |
179 |
180 | /**
181 | * Gets the fill color.
182 | *
183 | * @return the fill color
184 | */
185 |
186 | public static Color getFillColor()
187 | {
188 | return fillColor;
189 | }
190 |
191 |
192 |
193 | /**
194 | * Sets the fill color.
195 | *
196 | * @param color new fill color
197 | */
198 |
199 | public static void setFillColor (Color color)
200 | {
201 | fillColor = color;
202 | }
203 |
204 |
205 |
206 | /**
207 | * Prevent creation of instances outside of this class.
208 | */
209 |
210 | private Grid()
211 | {
212 | }
213 |
214 |
215 |
216 | /**
217 | * Renders the component.
218 | *
219 | * @param g graphics canvas
220 | */
221 |
222 | public void paint (Graphics g)
223 | {
224 | Dimension d = getSize();
225 |
226 | if (gridColor != null)
227 | {
228 | g.setColor(gridColor);
229 | g.drawRect(0, 0, d.width - 1, d.height - 1);
230 | }
231 |
232 | if (fillColor != null)
233 | {
234 | Graphics2D g2d = (Graphics2D) g;
235 | g2d.setComposite
236 | (AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.25f));
237 | g2d.setPaint(fillColor);
238 | g2d.fill(new Rectangle(1, 1, d.width - 1, d.height - 1));
239 | }
240 | }
241 |
242 |
243 |
244 | }
245 |
--------------------------------------------------------------------------------
/src/example2/Toggle1.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ====================================================================
3 | *
4 | * The Clearthought Software License, Version 1.0
5 | *
6 | * Copyright (c) 2001 Daniel Barbalace. All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * 2. The original software may not be altered. However, the classes
16 | * provided may be subclasses as long as the subclasses are not
17 | * packaged in the info.clearthought package or any subpackage of
18 | * info.clearthought.
19 | *
20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, AFFILATED BUSINESSES,
24 | * OR ANYONE ELSE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 | * SUCH DAMAGE.
32 | * ====================================================================
33 | */
34 |
35 |
36 |
37 | package example2;
38 |
39 |
40 |
41 | import java.awt.*;
42 | import java.awt.event.*;
43 | import javax.swing.*;
44 | import java.util.*;
45 | import info.clearthought.layout.TableLayout;
46 |
47 |
48 |
49 | /**
50 | * Example of components spanning cells.
51 | *
52 | * @author Daniel E. Barbalace
53 | * @version 1.0, June 14, 2005
54 | */
55 |
56 | public class Toggle1 implements ActionListener
57 | {
58 |
59 |
60 |
61 | /** Instance of TableLayout we are using */
62 | private static TableLayout layout;
63 |
64 | /** Checkbox that indicates whether or not to notify the user when the
65 | Internet connection goes down. */
66 | private static JCheckBox checkboxNotify;
67 |
68 | /** Container using the layout */
69 | private static Container container;
70 |
71 |
72 |
73 | /**
74 | * Runs the program.
75 | */
76 |
77 | public static void main (String args[])
78 | {
79 | // Create frame
80 | JFrame frame = new JFrame("Local Area Connection - Primary Properties");
81 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
82 |
83 | // Items to display in list control
84 | Vector listElement = new Vector();
85 | listElement.add("Client for Microsoft Networks");
86 | listElement.add("File and Print Sharing for Microsoft Networks");
87 | listElement.add("QoS Packet Scheduler");
88 | listElement.add("Microsoft TCP/IP version 6");
89 | listElement.add("Internet Protocol (TCP/IP");
90 |
91 | // Create controls
92 | JLabel labelConnect = new JLabel("Connect using:");
93 | JTextField textfieldConnect = new JTextField("Intel(R) PRO/100 VE Network Connection");
94 | JButton buttonConfigure = new JButton("Configure...");
95 | JLabel labelUse = new JLabel("This connection uses the following items:");
96 | JList list = new JList(listElement);
97 | JScrollPane scrollPane = new JScrollPane(list);
98 | JButton buttonInstall = new JButton("Install");
99 | JButton buttonUninstall = new JButton("Uninstall");
100 | JButton buttonProperties = new JButton("Properties");
101 | JCheckBox checkboxShowIcon = new JCheckBox("Show icon in notification area when connected");
102 | checkboxNotify = new JCheckBox("Notify me when this connection has limited or no connectivity");
103 | checkboxNotify.addActionListener(new Toggle1());
104 | JLabel labelTimeout = new JLabel("Timeout:");
105 | JTextField textfieldTimeout = new JTextField();
106 | JButton buttonOK = new JButton("OK");
107 | JButton buttonCancel = new JButton("Cancel");
108 |
109 | // Create and set layout
110 | double p = TableLayout.PREFERRED;
111 | double border = 10;
112 | double emptySpace = 10;
113 | double [] columnSize = {border, 1.0 / 3.0, TableLayout.FILL, 1.0 / 3.0, border};
114 | double [] rowSize = {border, border};
115 | layout = new TableLayout(columnSize, rowSize);
116 | layout.setVGap(2);
117 | layout.setHGap(5);
118 | container = frame.getContentPane();
119 | container.setLayout(layout);
120 |
121 | // Add controls
122 | layout.insertRow(1, p);
123 | container.add(labelConnect, "1, 1, 3, 1");
124 | layout.insertRow(2, p);
125 | container.add(textfieldConnect, "1, 2, 2, 2");
126 | container.add(buttonConfigure, "3, 2");
127 | layout.insertRow(3, emptySpace);
128 | layout.insertRow(4, p);
129 | container.add(labelUse, "1, 4, 3, 4");
130 | layout.insertRow(5, TableLayout.FILL);
131 | container.add(scrollPane, "1, 5, 3, 5");
132 | layout.insertRow(6, p);
133 | container.add(buttonInstall, "1, 6");
134 | container.add(buttonUninstall, "2, 6");
135 | container.add(buttonProperties, "3, 6");
136 | layout.insertRow(7, emptySpace);
137 | layout.insertRow(8, p);
138 | container.add(checkboxShowIcon, "1, 8, 3, 8");
139 | layout.insertRow(9, p);
140 | container.add(checkboxNotify, "1, 9, 3, 9");
141 | layout.insertRow(10, p);
142 | container.add(labelTimeout, "1, 10, RIGHT, CENTER");
143 | container.add(textfieldTimeout, "2, 10, 3, 10");
144 | layout.insertRow(11, emptySpace);
145 | layout.insertRow(12, p);
146 | container.add(buttonOK, "2, 12");
147 | container.add(buttonCancel, "3, 12");
148 |
149 | // Note: We don't want to show the timeout row initially because the
150 | // checkbox will not be checked. However, we want to include the
151 | // timeout row's height in the calculation done by Frame.pack().
152 | // So we call updateDynamicRows() after pack() has been called.
153 |
154 | // Show frame
155 | frame.pack();
156 | updateDynamicRows();
157 | frame.setVisible(true);
158 | frame.toFront();
159 | }
160 |
161 |
162 |
163 | /**
164 | * Invoked when the checkbox is toggled.
165 | */
166 |
167 | public void actionPerformed (ActionEvent e)
168 | {
169 | updateDynamicRows();
170 | }
171 |
172 |
173 |
174 | /**
175 | * Updates the visibility of dynamic rows.
176 | */
177 |
178 | private static void updateDynamicRows()
179 | {
180 | layout.setRow(10, checkboxNotify.isSelected() ? TableLayout.PREFERRED : 0);
181 | container.invalidate();
182 | container.validate();
183 | }
184 |
185 |
186 |
187 | }
188 |
--------------------------------------------------------------------------------
/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 | 12 | Welcome to the TableLayout project homepage! 13 |
14 | 15 |16 | TableLayout is a totally free layout manager designed to make creating user interfaces 17 | fast and easy. It can do anything GridBagLayout can do and much, much more. Yet it 18 | is remarkably simple and easy to use. 19 |
20 | 21 |22 | TableLayout uses concepts that everyone is familiar with such as spreadsheet-like 23 | rows, columns, and cells; and word processing justifications like left, center, right, 24 | and full. Consequentially, creating interfaces takes minutes instead of hours. 25 | Read the tutorial articles below to quickly get familiar with TableLayout. 26 | Once you do, you will never want to use another layout manager again! 27 |
28 | 29 |30 | Since its publication in 2002, TableLayout has rapidly become the most popular third 31 | party layout manager in the world. References to it can be found in languages from 32 | German to Japanese, and it has been used as a teaching aid in classes taught at 33 | the Massachusetts Institute of Technology (MIT). Join the thousands of developers 34 | who have been liberated from tedious GUI programming. 35 |
36 | 37 || 41 | |
42 |
43 |
44 |
45 | |
46 |
47 |
48 | Current Release
49 |
50 | 51 | Binaries, source, JavaDoc, and extensions... 52 | |
53 |
| 57 | |
58 |
59 |
60 |
61 | |
62 |
63 |
64 | License
65 |
66 | 67 | The license for TableLayout. 68 | |
69 |
| 76 | |
77 |
78 |
79 |
80 | |
81 |
82 |
83 | Testimonies
84 |
85 | 86 | Quotes from software engineers who have used TableLayout and provided unsolicited feedback... 87 | |
88 |
| 92 | |
93 |
94 |
95 |
96 | |
97 |
98 |
99 | History
100 |
101 | 102 | The history and future of TableLayout. 103 | |
104 |
| 111 | |
112 |
113 |
114 |
115 | |
116 |
117 |
118 | TableLayout Tutorial, Part 1: Introduction
119 |
120 | 121 | Tired of using GridBagLayout or nesting panels to get the layout you want? 122 | Learn about TableLayout and what it can do for you. Write GUIs in minutes 123 | instead of hours. 124 | |
125 |
| 129 | |
130 |
131 |
132 |
133 | |
134 |
135 |
136 | TableLayout Tutorial, Part 2: Building Powerful GUIs
137 |
138 | 139 | Create much more powerful interfaces using techiques such as cell spanning, toggling 140 | groups of controls, scrolling, and component orientation. 141 | |
142 |
| 146 | |
147 |
148 |
149 |
150 | |
151 |
152 |
153 | Table Dancer
154 |
155 | 156 | This is an article about TableLayout that was published by the German software magazine 157 | Javamagazin. An English translation provided by Google is 158 | here. 160 | A larger copy of the picture to the left is provided 161 | here. 162 | |
163 |
| 170 | |
171 |
172 |
173 |
174 | |
175 |
176 |
177 | Totally Gridbag: An animated weblog entry
178 |
179 | 180 | A funny flash cartoon illustrating the frustrations of using layout managers. 181 | |
182 |
| 189 | |
190 |
191 |
192 |
193 | |
194 |
195 |
196 | JComboBoxFixed
197 |
198 | 199 | A fix for a bug in JComboBox that causes ActionEvents to be fired when navigating by keys. 200 | |
201 |
12 | TableLayout is a well-tested and well-used layout manager. It has been around in one form or another 13 | since 1996. Over many years, TableLayout has been refined. It may now be as perfect as a layout manager 14 | can be. So it is unlikely that there will be subsequent version unless someone suggests a change that 15 | would significantly improve Tablelayout, and that change must be added to the core of TableLayout. 16 |
17 | 18 |19 | However, ancillary support for TableLayout may be added to this site. Some suggestions have been to add 20 | TableLayout support to Netbeans, Forte, JBuilder, and other RAD tools. Since such ancillary "plug-ins" 21 | are not necessary to use TableLayout, and may be tool or JDK specific, they would be provided as 22 | extension jar files. 23 |
24 | 25 |26 | The main goal of the TableLayout project is to submit TableLayout to Sun for entry into JDK 1.6. 27 | If you would like to see this happen, you can voice your opinion 28 | here. 29 |
30 | 31 |32 | The brief history of TableLayout is... 33 |
34 | 35 || 1996-2001 | 38 |39 | TableLayout was written to the JDK 1.0 and JDK 1.1 using custom classes for LinkedLists, etc. 40 | This version of TableLayout was never published, but was used by the author extensively. 41 | Most of the layout manager was written up front, but over time a few useful features were added. 42 | | 43 |
| 2001 | 48 |
49 | TableLayout was modified to use only core Java classes from the JDK including the JDK 1.2 collections
50 | framework. Non-standard classes were removed. The API for TableLayout was modified to be more
51 | consistent with established Java conventions. 52 | 53 | The author contacted Sun and submitted the layout manager. A Sun representative asked the author 54 | to write an article about TableLayout for The Swing Connection. The article was submitted to Sun 55 | and reviewed along with the layout manager by several Sun architects. TableLayout was further 56 | refined based on the feedback from Sun. The article and TableLayout were published on Sun's 57 | website. This was the first official version of TableLayout. 58 | |
59 |
| 2002 | 64 |65 | The author received many positive messages from users across the world. Some of the messages 66 | contained requests for features like justification for components occupying more than one cell. 67 | The requests that would most improve TableLayout were implemented. 68 | | 69 |
| 2002 | 74 |75 | An extension jar for TableLayout was created based on an idea from a developer to use the 76 | persistent delagation mechanism introduced in JDK 1.4 to save and load frames. 77 | | 78 |
| 2003 Oct 1 | 83 |84 | A fix is provided for a problem dealing with the preferred size of containers containing 85 | components spanning multiple cells with absolute widths/heights. 86 | | 87 |
| 2003 Nov 4 | 92 |
93 | TableLayout now supports component orientation. Two new justifcations have been added:
94 | LEADING and TRAILING. Leading justification means components are left justified if
95 | their container is left-oriented and right justified if their container is right-oriented.
96 | Trailing justification is opposite. 97 | 98 | Also, a constructor in the form new TableLayout(double [] columns, double [] rows)
99 | has been added for convenience.
100 | |
101 |
| 2003 Dec 11 | 106 |107 | Corrected vertical gaps. 108 | | 109 |
| 2004 Feb 15 | 114 |115 | Added leading and trailing constaints to TableLayoutConstraints.toString method. 116 | | 117 |
| 2004 May 9 | 122 |123 | Added caching of the methodGetComponentOrientation field in TableLayout. 124 | | 125 |
| 2005 April 8 | 130 |
131 | Fixed leak of XML Decoder in TableLayoutPersistenceDelegate class located in TableLayoutPersistenceDelegate.jar. 132 | Fixed a javadoc comment for TableLayoutConstraints constructor. 133 | Fixed a bug in getting the minimum size of a container that used preferred column/row sizes and getting 134 | the preferred size of a container that used minimum column/row sizes. 135 | |
136 |
| 2005 May 5 | 140 |141 | Updated the javadoc description of TableLayout. 142 | | 143 |
| 2005 June 15 | 148 |149 | Added convenience constructors to TableLayoutConstraints. Fixed the sizes of cell spanning components 150 | that were not full justified. They were getting extra space from gaps. 151 | | 152 |
| 2005 September 14 | 157 |158 | TableLayout no longer flips container insets for right-to-left oriented containers since most java.awt 159 | layouts and Swing components do not (FlowLayout is the exception). Minor performance tweak in 160 | the layoutContainer method. Compatibility fix with old JDKs that did not support component orientation. 161 | | 162 |
| 2007 March 6 | 167 |168 | TableLayoutConstraints constructor was setting LEADING justification to FULL due to an omission. 169 | Fixed this constructor. 170 | | 171 |
| 2009 May 10 | 176 |177 | Adjusted calculation for preferred and minimum sizes of a column/row to consider gaps that contribute to the size 178 | of a multicell component. Updated license to be more compatible with most open source licenses. 179 | | 180 |
| 2009 August 26 | 185 |186 | Added ComponentArranger builder for creating layouts. Change access setting of insertCr from public to protected. 187 | Users should call insertColumn or insertRow instead. Fixed many spelling errors in JavaDoc. (Thanks to Eclipse 188 | for including a spellchecker!) 189 | | 190 |
194 | Back to project home 195 |
196 | 197 | 198 | -------------------------------------------------------------------------------- /src/exampleSupport/BufferedFrame.java: -------------------------------------------------------------------------------- 1 | package exampleSupport; 2 | 3 | 4 | 5 | import java.awt.*; 6 | import java.awt.event.*; 7 | 8 | 9 | 10 | /** 11 | * This class implements a double buffered window that closes when the user 12 | * presses the "close window" button. 13 | * 14 | * @author Daniel E. Barbalace 15 | */ 16 | 17 | public class BufferedFrame extends Frame implements 18 | java.awt.event.WindowListener, 19 | java.awt.event.ComponentListener 20 | { 21 | 22 | 23 | 24 | 25 | /** Offscreen buffer used for double buffering */ 26 | protected Image offscreen; 27 | 28 | /** Offscreen buffer's graphics content */ 29 | protected Graphics h; 30 | 31 | /** Size of offscreen buffer */ 32 | protected Dimension o; 33 | 34 | /** Smallest size the window may be */ 35 | protected Dimension smallest; 36 | 37 | 38 | 39 | /** 40 | * Constructs the frame. 41 | */ 42 | 43 | public BufferedFrame () 44 | { 45 | this (null); 46 | } 47 | 48 | 49 | 50 | /** 51 | * Constructs the frame. 52 | * 53 | * @param title text to display in window title area 54 | */ 55 | 56 | public BufferedFrame (String title) 57 | { 58 | // Call parent constructor 59 | super (title); 60 | 61 | // Set minum size to default to 0x0 62 | smallest = new Dimension(0, 0); 63 | 64 | // Initialize double buffering 65 | this.offscreen = null; 66 | this.h = null; 67 | 68 | // This class is its own window listener so it can handle window events 69 | addWindowListener (this); 70 | 71 | // Prevent going below minimum size and generate offscreen buffer for 72 | // double buffering 73 | addComponentListener (this); 74 | 75 | // Create offscreen canvas for double buffering 76 | createOffscreenBuffer(); 77 | } 78 | 79 | 80 | 81 | /** 82 | * Sets the minimum size of this window. If the window is resized to be 83 | * smaller than this size, the window will be enlarged enough to meet this size. 84 | * 85 | * @param size minimum size of this window 86 | */ 87 | 88 | public void setMinimumSize (Dimension d) 89 | { 90 | smallest.width = d.width; 91 | smallest.height = d.height; 92 | } 93 | 94 | 95 | 96 | /** 97 | * Sets the minimum size of this window. If the window is resized to be 98 | * smaller than this size, the window will be enlarged enough to meet this size. 99 | * 100 | * @param width minimum width of this window 101 | * @param height minimum height of this window 102 | */ 103 | 104 | public void setMinimumSize (int width, int height) 105 | { 106 | smallest.width = width; 107 | smallest.height = height; 108 | } 109 | 110 | 111 | 112 | /** 113 | * Gets the minimum size of this window. If the window is resized to be 114 | * smaller than this size, the window will be enlarged enough to meet this size. 115 | * 116 | * @return minimum size of this window 117 | */ 118 | 119 | public Dimension getMinimumSize () 120 | { 121 | return new Dimension(smallest); 122 | } 123 | 124 | 125 | 126 | /** 127 | * Updates this component. This method only does one thing: callspaint
128 | * .
129 | *
130 | * @param g Graphics context
131 | */
132 |
133 | public void update (Graphics g)
134 | {
135 | paint (g);
136 | }
137 |
138 |
139 |
140 | /**
141 | * Renders this frame using double buffering.
142 | *
143 | * @param g graphics canvas
144 | */
145 |
146 | public void paint (Graphics g)
147 | {
148 | // Make sure offscreen buffer exists
149 | if( h == null )
150 | // Abort painting, there is no space on which to draw
151 | return;
152 |
153 | // Set clip area
154 | Rectangle clip = g.getClip().getBounds();
155 | h.setClip (clip);
156 |
157 | // Fill background color
158 | h.setColor (getBackground());
159 | Dimension d = getSize();
160 | h.fillRect (0, 0, d.width, d.height);
161 |
162 | // Call parent's paint
163 | super.paint (h);
164 |
165 | // Render canvas
166 | g.drawImage (offscreen, 0, 0, null);
167 | }
168 |
169 |
170 |
171 | /**
172 | * Creates the offscreen buffer used for double buffering.
173 | */
174 |
175 | private void createOffscreenBuffer ()
176 | {
177 | // Get size of frame
178 | o = getToolkit().getScreenSize();
179 |
180 | // Make sure both width and height are positive to avoid a non-fatal
181 | // exception when creating an image for double buffering
182 | if( (o.width <= 0) || (o.height <= 0) )
183 | // Abort function, there is no space on which to draw
184 | return;
185 |
186 | // Compensate for insets
187 | o.width += 10;
188 | o.height += 10;
189 |
190 | // Remove previous background image
191 | if( offscreen != null )
192 | {
193 | // Dispose of offscreen canvas
194 | offscreen.flush();
195 | offscreen = null;
196 | System.gc();
197 | }
198 |
199 | // Create offscreen canvas
200 | offscreen = Misc.createImage(o.width, o.height);
201 | h = offscreen.getGraphics();
202 | }
203 |
204 |
205 |
206 | /**
207 | * Disposes of this frame and all the resources it uses.
208 | */
209 |
210 | public void dispose ()
211 | {
212 | // Dispose of offscreen canvas
213 | if (offscreen != null)
214 | offscreen.flush();
215 |
216 | // Null all references
217 | h = null;
218 | o = null;
219 | smallest = null;
220 | offscreen = null;
221 |
222 | // Garbage collection
223 | System.gc();
224 |
225 | // Call parent dispose
226 | super.dispose();
227 | }
228 |
229 |
230 |
231 | //******************************************************************************
232 | //** java.awt.event.ComponentListener methods ***
233 | //******************************************************************************
234 |
235 |
236 |
237 | /**
238 | * Invoked when component has been resized.
239 | */
240 |
241 | public void componentResized (ComponentEvent e)
242 | {
243 | // Assume good size
244 | boolean resize = false;
245 |
246 | // Get size
247 | Dimension d = getSize();
248 |
249 | // Make sure width is at least minimum
250 | if( d.width < smallest.width )
251 | {
252 | d.width = smallest.width;
253 | resize = true;
254 | }
255 |
256 | // Make sure height is at least minimum
257 | if( d.height < smallest.height )
258 | {
259 | d.height = smallest.height;
260 | resize = true;
261 | }
262 |
263 | // Resize if necessary
264 | if( resize )
265 | // Set size of this control
266 | setSize (d);
267 |
268 | // Make sure frame size does not exceed offscreen buffer size. This
269 | // could happen if the end user changes resolution at runtime.
270 | if( (d.width > o.width) || (d.height > o.height) )
271 | createOffscreenBuffer();
272 |
273 | // Erase previous image on offscreen canvas
274 | int imageWidth = offscreen.getWidth(null);
275 | int imageHeight = offscreen.getWidth(null);
276 |
277 | h.setColor (Color.white);
278 | h.fillRect (d.width, 0, imageWidth - d.width, imageHeight);
279 | h.fillRect (0, d.height, d.width, imageHeight - d.height);
280 | }
281 |
282 |
283 |
284 | /**
285 | *Invoked when component has been moved.
286 | */
287 |
288 | public void componentMoved (ComponentEvent e)
289 | {
290 | }
291 |
292 |
293 |
294 | /**
295 | * Invoked when component has been shown.
296 | */
297 |
298 | public void componentShown (ComponentEvent e)
299 | {
300 | }
301 |
302 |
303 |
304 | /**
305 | * Invoked when component has been hidden.
306 | */
307 |
308 | public void componentHidden (ComponentEvent e)
309 | {
310 | }
311 |
312 |
313 |
314 | //******************************************************************************
315 | //** java.awt.event.WindowListener methods ***
316 | //******************************************************************************
317 |
318 |
319 |
320 | /**
321 | * Invoked when a window has been opened.
322 | */
323 |
324 | public void windowOpened (WindowEvent e)
325 | {
326 | }
327 |
328 |
329 |
330 | /**
331 | * Invoked when a window is in the process of being closed. The close operation
332 | * can be overridden at this point. This method does only one thing: terminates
333 | * the application. Derived classes want to override this method without
334 | * calling BufferedFrame.windowClosing if they terminate the application
335 | * themselves.
336 | */
337 |
338 | public void windowClosing (WindowEvent e)
339 | {
340 | // Terminate program
341 | System.exit (0);
342 | }
343 |
344 |
345 |
346 | /**
347 | * Invoked when a window has been closed. This method will not be called since
348 | * windowClosing terminates the application.
349 | */
350 |
351 | public void windowClosed (WindowEvent e)
352 | {
353 | }
354 |
355 |
356 |
357 | /**
358 | * Invoked when a window is iconified.
359 | */
360 |
361 | public void windowIconified (WindowEvent e)
362 | {
363 | }
364 |
365 |
366 |
367 | /**
368 | * Invoked when a window is de-iconified.
369 | */
370 |
371 | public void windowDeiconified (WindowEvent e)
372 | {
373 | }
374 |
375 |
376 |
377 | /**
378 | * Invoked when a window is activated.
379 | */
380 |
381 | public void windowActivated (WindowEvent e)
382 | {
383 | }
384 |
385 |
386 |
387 | /**
388 | * Invoked when a window is de-activated.
389 | */
390 |
391 | public void windowDeactivated (WindowEvent e)
392 | {
393 | }
394 |
395 |
396 |
397 | }
398 |
--------------------------------------------------------------------------------
/src/example2/BorderSimple.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ====================================================================
3 | *
4 | * The Clearthought Software License, Version 1.0
5 | *
6 | * Copyright (c) 2001 Daniel Barbalace. All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * 2. The original software may not be altered. However, the classes
16 | * provided may be subclasses as long as the subclasses are not
17 | * packaged in the info.clearthought package or any subpackage of
18 | * info.clearthought.
19 | *
20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, AFFILATED BUSINESSES,
24 | * OR ANYONE ELSE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 | * SUCH DAMAGE.
32 | * ====================================================================
33 | */
34 |
35 |
36 |
37 | package example2;
38 |
39 |
40 |
41 | import java.awt.*;
42 | import java.awt.event.*;
43 | import java.io.*;
44 | import java.net.*;
45 | import javax.swing.*;
46 | import info.clearthought.layout.*;
47 |
48 |
49 |
50 | /**
51 | * BorderSimple demonstrates how to create a simple border.
52 | *
53 | * @author Daniel E. Barbalace
54 | * @version 1.0, Jun 17, 2005
55 | */
56 |
57 | public class BorderSimple implements ActionListener
58 | {
59 |
60 |
61 |
62 | /** Main frame */
63 | private JFrame frame;
64 |
65 | /** Used to display the path of the file being displayed */
66 | private JLabel labelFilename;
67 |
68 | /** When selected, files will be displayed as web pages */
69 | private JRadioButton radioWebPage;
70 |
71 | /** When selected, files will be displayed as text */
72 | private JRadioButton radioText;
73 |
74 | /** Used to display HTML files as web pages */
75 | private JEditorPane paneWeb;
76 |
77 | /** Used to display HTML files as text */
78 | private JTextPane paneText;
79 |
80 | /** Used to scroll document view */
81 | private JScrollPane scrollPane;
82 |
83 | /** Open file menu item */
84 | private JMenuItem menuOpenFile;
85 |
86 | /** Open URL item */
87 | private JMenuItem menuOpenUrl;
88 |
89 | /** Exit menu item */
90 | private JMenuItem menuExit;
91 |
92 |
93 |
94 | /**
95 | * Runs the program.
96 | */
97 |
98 | public static void main (String args[])
99 | {
100 | new BorderSimple();
101 | }
102 |
103 |
104 |
105 | /**
106 | * Creates the application's GUI.
107 | */
108 |
109 | public BorderSimple()
110 | {
111 | // Create frame
112 | frame = new JFrame("Simple Border");
113 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
114 |
115 | // Create menu
116 | JMenuBar menuBar = new JMenuBar();
117 | JMenu menu = new JMenu("File");
118 | menuOpenFile = menu.add("Open File");
119 | menuOpenUrl = menu.add("Open URL");
120 | menuExit = menu.add("Exit");
121 | menuOpenFile.addActionListener(this);
122 | menuOpenUrl.addActionListener(this);
123 | menuExit.addActionListener(this);
124 | menuBar.add(menu);
125 | frame.setJMenuBar(menuBar);
126 |
127 | // Create controls
128 | JLabel labelFile = new JLabel("File:");
129 | labelFilename = new JLabel("");
130 | JLabel labelView = new JLabel("View as:");
131 | radioWebPage = new JRadioButton("Web Page");
132 | radioText = new JRadioButton("Text");
133 | ButtonGroup groupView = new ButtonGroup();
134 | groupView.add(radioWebPage);
135 | groupView.add(radioText);
136 | radioWebPage.setSelected(true);
137 | radioWebPage.addActionListener(this);
138 | radioText.addActionListener(this);
139 | paneWeb = new JEditorPane();
140 | paneWeb.setEditable(false);
141 | paneText = new JTextPane();
142 | paneText.setEditable(false);
143 |
144 | scrollPane = new JScrollPane(paneWeb);
145 | scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
146 | scrollPane.setPreferredSize(new Dimension(600, 400));
147 | scrollPane.setMinimumSize(new Dimension(10, 10));
148 |
149 | // Create and set layout
150 | double p = TableLayout.PREFERRED;
151 | double border = 10;
152 | double [] columnSize = {border, p, p, p, TableLayout.FILL, border};
153 | double [] rowSize = {border, p, p, TableLayout.FILL, border};
154 | TableLayout layout = new TableLayout(columnSize, rowSize);
155 | layout.setHGap(5);
156 | Container container = frame.getContentPane();
157 | container.setLayout(layout);
158 |
159 | // Add controls
160 | container.add(labelFile, "1, 1, RIGHT, BOTTOM");
161 | container.add(labelFilename, "2, 1, 4, 1");
162 | container.add(labelView, "1, 2, RIGHT, CENTER");
163 | container.add(radioWebPage, "2, 2");
164 | container.add(radioText, "3, 2");
165 | container.add(scrollPane, "1, 3, 4, 3");
166 |
167 | // Show one html file by default
168 | setPath("/sample.html");
169 |
170 | // Show frame
171 | frame.pack();
172 | frame.setVisible(true);
173 | frame.toFront();
174 | }
175 |
176 |
177 |
178 | /**
179 | * Sets the path of the document to view.
180 | *
181 | * @param path full or relative path of document
182 | */
183 |
184 | private void setPath (String path)
185 | {
186 | // Attempt to open file in jar
187 | URL url = BorderSimple.class.getResource(path);
188 |
189 | // Attempt to open a full URL
190 | if (url == null)
191 | {
192 | try
193 | {
194 | url = new URL(path);
195 | }
196 | catch (MalformedURLException e) {}
197 | }
198 |
199 | // Attempt to open a local file
200 | if (url == null)
201 | {
202 | try
203 | {
204 | File file = new File(path);
205 | url = file.toURL();
206 | }
207 | catch (MalformedURLException e) {}
208 | }
209 |
210 | // If any of the attempts succeeded, open the url
211 | if (url != null)
212 | {
213 | try
214 | {
215 | paneWeb.setPage(url);
216 | paneText.setText(getContent(url));
217 | labelFilename.setText(path);
218 | }
219 | catch (IOException e)
220 | {
221 | paneWeb.setText("");
222 | paneText.setText("");
223 | labelFilename.setText("");
224 | System.err.println("Attempted to read a bad URL: " + url);
225 | }
226 | }
227 | else
228 | {
229 | System.err.println("Couldn't find file: " + path);
230 | }
231 | }
232 |
233 |
234 |
235 | /**
236 | * Gets the contents of a URL as a string.
237 | *
238 | * @param url document to get
239 | *
240 | * @return a string containing the URL's contents
241 | */
242 |
243 | private String getContent (URL url)
244 | {
245 | StringBuffer content = new StringBuffer();
246 |
247 | try
248 | {
249 | String line = "";
250 | BufferedReader input = new BufferedReader(new InputStreamReader(url.openStream()));
251 |
252 | while (line != null)
253 | {
254 | content.append(line);
255 |
256 | if (line.length() > 0)
257 | content.append('\n');
258 |
259 | line = input.readLine();
260 | }
261 |
262 | input.close();
263 | }
264 | catch (MalformedURLException me) {}
265 | catch (IOException e) {}
266 |
267 | return content.toString();
268 | }
269 |
270 |
271 |
272 | /**
273 | * Invoked when one of the radio buttons is selected.
274 | */
275 |
276 | public void actionPerformed (ActionEvent e)
277 | {
278 | Object source = e.getSource();
279 |
280 | if (source == radioWebPage)
281 | scrollPane.setViewportView(paneWeb);
282 | else if (source == radioText)
283 | scrollPane.setViewportView(paneText);
284 | else if (source == menuOpenFile)
285 | {
286 | JFileChooser fc = new JFileChooser();
287 | int returnVal = fc.showOpenDialog(menuOpenFile);
288 |
289 | if (returnVal == JFileChooser.APPROVE_OPTION)
290 | {
291 | File file = fc.getSelectedFile();
292 | setPath(file.getPath());
293 | }
294 | }
295 | else if (source == menuOpenUrl)
296 | {
297 | String message = "URL to open";
298 | String s = (String) JOptionPane.showInputDialog
299 | (frame, message, "Open URL", JOptionPane.PLAIN_MESSAGE, null, null, null);
300 |
301 | if ((s != null) && (s.length() > 0))
302 | setPath(s);
303 | }
304 | else if (source == menuExit)
305 | System.exit(0);
306 | }
307 |
308 |
309 |
310 | }
311 |
--------------------------------------------------------------------------------
/src/exampleSupport/BlankLabel.java:
--------------------------------------------------------------------------------
1 | package exampleSupport;
2 |
3 |
4 |
5 | import java.awt.*;
6 | import java.awt.event.*;
7 |
8 |
9 |
10 | /**
11 | * This class displays static text like the java.awt.Label class. However,
12 | * unlike Label, BlankLabel is a lightweight component with a transparent
13 | * background. Thus, it can placed on top of a background image without
14 | * covering the image.
15 | *
16 | * @author Daniel E. Barbalace
17 | */
18 |
19 | public class BlankLabel extends Component implements
20 | java.awt.event.ComponentListener
21 | {
22 |
23 |
24 |
25 | // The following constants are used to justify the label.
26 | /** Indicates that the label's text should be left justified. */
27 | public static final int ALIGN_LEFT = 0;
28 | /** Indicates that the label's text should be centered justified. */
29 | public static final int ALIGN_CENTER = 1;
30 | /** Indicates that the label's text should be right justified. */
31 | public static final int ALIGN_RIGHT = 2;
32 |
33 |
34 |
35 | /** Font used when BlankLabel is created */
36 | protected static Font defaultFont = null;
37 |
38 | /** Text displayed by label */
39 | protected String label;
40 |
41 | /** Label actually printed on button */
42 | protected String shownLabel;
43 |
44 | /** Graphics context */
45 | protected Graphics graphics = null;
46 |
47 | /** Label alignment */
48 | protected int alignment = ALIGN_LEFT;
49 |
50 | /** Height (in pixels) of label */
51 | protected int textHeight;
52 |
53 | /** Width (in pixels) of label */
54 | protected int textWidth;
55 |
56 | /** Horizontal offset to first character of label */
57 | protected int textInsetX;
58 |
59 | /** Vertical offset to baseline of label */
60 | protected int textInsetY;
61 |
62 |
63 |
64 | /**
65 | * To construct a BlankLabel with a specified label.
66 | *
67 | * @param label text to be displayed by the label. If label is
68 | * null, no label is displayed.
69 | */
70 |
71 | public BlankLabel (String label)
72 | {
73 | // Call parent constructor
74 | super();
75 |
76 | // Set label; if blank, use no label
77 | if (label == null)
78 | this.label = "";
79 | else
80 | this.label = label;
81 |
82 | // Use the default font if available
83 | if (defaultFont != null)
84 | setFont (defaultFont);
85 |
86 | // This component must know when it has been resized
87 | addComponentListener (this);
88 | }
89 |
90 |
91 |
92 | /**
93 | * Sets the font used by all BlankLabels that do not have their font explicitly
94 | * set. The change only affects new BlankLabels. If this method is not called
95 | * or null is specified for defaultFont, the default component font
96 | * is used.
97 | *
98 | * @param defaultFont font to use as the default font for all new BlankLabels
99 | */
100 |
101 | public static void setDefaultFont (Font defaultFont)
102 | {
103 | BlankLabel.defaultFont = defaultFont;
104 | }
105 |
106 |
107 |
108 | /**
109 | * Changes the font being used by the label.
110 | *
111 | * @param font font to use
112 | */
113 |
114 | public void setFont (Font font)
115 | {
116 | // Change font
117 | super.setFont (font);
118 |
119 | // If the font has been changed, the shown label may need adjusting
120 | updateShownLabel();
121 | }
122 |
123 |
124 |
125 | /**
126 | * Gets the text of the label.
127 | *
128 | * @return the text of the label as a string
129 | */
130 |
131 | public String getText ()
132 | {
133 | return label;
134 | }
135 |
136 |
137 |
138 | /**
139 | * Sets the text of the label.
140 | *
141 | * @param label new label to display. If label is null, no label
142 | * is displayed.
143 | *
144 | * @return the text of the label as a string
145 | */
146 |
147 | public void setText (String label)
148 | {
149 | // Set the label's text; null means that no label is used
150 | if (label == null)
151 | this.label = "";
152 | else
153 | this.label = label;
154 |
155 | // If the text has been changed, the shown label may need adjusting
156 | updateShownLabel();
157 |
158 | // Indicate that container may need to layout out components
159 | invalidate();
160 |
161 | // Repaint the label
162 | repaint();
163 | }
164 |
165 |
166 |
167 | /**
168 | * Sets the alignment of the label.
169 | *
170 | * @param alignment one of the following: ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT
171 | */
172 |
173 | public void setAlignment (int alignment)
174 | {
175 | this.alignment = alignment;
176 | repaint();
177 | }
178 |
179 |
180 |
181 | /**
182 | * Updates the control drawing properties.
183 | */
184 |
185 | protected void updateShownLabel ()
186 | {
187 | // Set font
188 | Font font = getFont();
189 |
190 | // Get dimensions of this canvas
191 | Dimension labelSize = getSize();
192 |
193 | // If the component is not yet visible, it will have no size. This means
194 | // purely static components, those that do not change size of position, will
195 | // never know their size until it's too late. This is a design flaw --
196 | // er, uh -- feature of the Abstract Window Toolkit. To prevent this code
197 | // from setting the shown label text to the empty screen, whenever the
198 | // component's size is 0 by 0, the entire label is shown -- that is,
199 | // everything that fits inside a 0x0 area is shown.
200 | if ((labelSize.width == 0) && (labelSize.height == 0))
201 | {
202 | shownLabel = label;
203 | return;
204 | }
205 |
206 | // Get font information
207 | FontMetrics fm = getFontMetrics(font);
208 | textHeight = fm.getHeight();
209 | textWidth = fm.stringWidth(label);
210 |
211 | // Make sure label is small enough to fit in button
212 | shownLabel = label;
213 |
214 | if (textWidth > labelSize.width)
215 | shownLabel = shownLabel + "...";
216 |
217 | try
218 | {
219 | // Keep removing a character from label until it fits or has no more
220 | // characters
221 | while (textWidth > labelSize.width)
222 | {
223 | shownLabel = shownLabel.substring(0, shownLabel.length() - 4) +
224 | "...";
225 |
226 | textWidth = fm.stringWidth(shownLabel);
227 | }
228 | }
229 | catch (StringIndexOutOfBoundsException error)
230 | {
231 | // Label has no more characters except "...", so make label empty
232 | shownLabel = "";
233 | }
234 |
235 | // Calculate where to put text baseline and first character
236 | textInsetX = (labelSize.width - textWidth) / 2;
237 | textInsetY = (labelSize.height - textHeight) / 2;
238 | }
239 |
240 |
241 |
242 | /**
243 | * Updates this component. This method only does one thing: calls paint
244 | * .
245 | *
246 | * @param g Graphics context
247 | */
248 |
249 | public void update (Graphics g)
250 | {
251 | // Call paint directly, instead of Component.update, to prevent flickering
252 | paint (g);
253 | }
254 |
255 |
256 |
257 | /**
258 | * Draws the label.
259 | *
260 | * @param g Graphics canvas
261 | */
262 |
263 | public void paint (Graphics g)
264 | {
265 | try
266 | {
267 | // Set font
268 | Font font = getFont();
269 | g.setFont (font);
270 |
271 | // Get font metrics
272 | FontMetrics fm = g.getFontMetrics();
273 | int textHeight = fm.getHeight();
274 | int textDescent = fm.getDescent();
275 | int textWidth = fm.stringWidth(shownLabel);
276 | int width = getSize().width;
277 |
278 | // Calculate offset based on alignment and control size
279 | int offset = 0;
280 |
281 | switch (alignment)
282 | {
283 | case ALIGN_LEFT : offset = 0; break;
284 | case ALIGN_CENTER : offset = (width - textWidth) / 2; break;
285 | case ALIGN_RIGHT : offset = width - textWidth; break;
286 | }
287 |
288 | // Draw text
289 | g.setColor (getForeground());
290 | g.drawString (shownLabel, offset, textHeight - textDescent);
291 | }
292 | catch (NullPointerException exception)
293 | {
294 | // sun.awt.windows.WFontMetrics craps out if paint is called before
295 | // the component is visible or if a time critical condition occurs. If
296 | // the component is not visible, there is no point in drawing it. If
297 | // the time critical condition occurs, a NullPointerException will
298 | // occur at both
299 | // sun.awt.windows.WFontMetrics.stringWidth(WFontMetrics.java:167) and
300 | // sun.awt.windows.WGraphics.drawString(WGraphics.java:199)
301 | // So this component cannot be rendered.
302 | }
303 | }
304 |
305 |
306 |
307 | /**
308 | * Gets the preferred size of this component. The preferred size is just enough
309 | * to fit the label.
310 | *
311 | * @return a dimension object indicating this component's preferred size.
312 | */
313 |
314 | public Dimension getPreferredSize()
315 | {
316 | Dimension dimension;
317 |
318 | try
319 | {
320 | // Get font metrics
321 | FontMetrics fm = getFontMetrics(getFont());
322 |
323 | // Set prefered size to be text size
324 | int textWidth = fm.stringWidth(label);
325 | int textHeight = fm.getHeight() + fm.getMaxDescent() - fm.getDescent();
326 | dimension = new Dimension(textWidth, textHeight);
327 | }
328 | catch (NullPointerException exception)
329 | {
330 | // Stupid AWT givens NullPointerException if getPreferredSize is called
331 | // before control is visible
332 | dimension = new Dimension(0, 0);
333 | }
334 |
335 | return dimension;
336 | }
337 |
338 |
339 |
340 | //******************************************************************************
341 | //*** java.awt.event.ComponentListener methods ***
342 | //******************************************************************************
343 |
344 |
345 |
346 | /**
347 | * Invoked when component has been resized.
348 | */
349 |
350 | public void componentResized (ComponentEvent e)
351 | {
352 | // If the component has been resized, the shown label may need adjusting
353 | if (e.getSource() == this)
354 | updateShownLabel();
355 | }
356 |
357 |
358 |
359 | /**
360 | * Invoked when component has been moved.
361 | */
362 |
363 | public void componentMoved (ComponentEvent e)
364 | {
365 | }
366 |
367 |
368 |
369 | /**
370 | * Invoked when component has been shown.
371 | */
372 |
373 | public void componentShown (ComponentEvent e)
374 | {
375 | }
376 |
377 |
378 |
379 | /**
380 | * Invoked when component has been hidden.
381 | */
382 |
383 | public void componentHidden (ComponentEvent e)
384 | {
385 | }
386 |
387 |
388 |
389 | }
390 |
--------------------------------------------------------------------------------
/src/example2/Toggle2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ====================================================================
3 | *
4 | * The Clearthought Software License, Version 1.0
5 | *
6 | * Copyright (c) 2001 Daniel Barbalace. All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * 2. The original software may not be altered. However, the classes
16 | * provided may be subclasses as long as the subclasses are not
17 | * packaged in the info.clearthought package or any subpackage of
18 | * info.clearthought.
19 | *
20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, AFFILATED BUSINESSES,
24 | * OR ANYONE ELSE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 | * SUCH DAMAGE.
32 | * ====================================================================
33 | */
34 |
35 |
36 |
37 | package example2;
38 |
39 |
40 |
41 | import java.awt.*;
42 | import java.awt.event.*;
43 |
44 | import javax.swing.*;
45 | import info.clearthought.layout.TableLayout;
46 | import info.clearthought.layout.TableLayoutConstraints;
47 |
48 |
49 |
50 | /**
51 | * Example of components spanning cells.
52 | *
53 | * @author Daniel E. Barbalace
54 | * @version 1.0, June 20, 2005
55 | */
56 |
57 | public class Toggle2 implements ActionListener
58 | {
59 |
60 |
61 |
62 | /** Indicates an internal office address */
63 | private static final String INTERNAL = "Internal";
64 |
65 | /** Indicates a domestic (US) address */
66 | private static final String DOMESTIC = "Domestic";
67 |
68 | /** Indicates an international (non-US) address */
69 | private static final String INTERNATIONAL = "International";
70 |
71 | /** Empty space for asthetics */
72 | private static double EMPTY_SPACE = 10;
73 |
74 | /** Instance of TableLayout we are using */
75 | private TableLayout layout;
76 |
77 | /** Container using the layout */
78 | private Container container;
79 |
80 | /** Identifies the type of address */
81 | private JComboBox comboType;
82 |
83 | // A whole bunch of controls that this application will use.
84 | JLabel labelOffice = new JLabel("Office");
85 | JTextField textOffice = new JTextField(5);
86 | JLabel labelBuilding = new JLabel("Building");
87 | JComboBox comboBuilding = new JComboBox(new String [] {"A", "B", "C"});
88 | JLabel labelStreet = new JLabel("Street");
89 | JLabel labelCity = new JLabel("City");
90 | JLabel labelState = new JLabel("State");
91 | JLabel labelZip = new JLabel("Zip Code");
92 | JLabel labelProvidence = new JLabel("Providence");
93 | JLabel labelCountry = new JLabel("Country");
94 | JTextField textStreet = new JTextField(25);
95 | JTextField textCity = new JTextField(25);
96 | JTextField textState = new JTextField(2);
97 | JTextField textZip = new JTextField(5);
98 | JTextField textProvidence = new JTextField(25);
99 | JTextField textCountry = new JTextField(25);
100 |
101 |
102 |
103 | /**
104 | * Runs the program.
105 | */
106 |
107 | public static void main (String args[])
108 | {
109 | new Toggle2();
110 | }
111 |
112 |
113 |
114 | public Toggle2()
115 | {
116 | // Create frame
117 | JFrame frame = new JFrame("Toggling Groups of Rows");
118 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
119 | frame.setResizable(false);
120 |
121 | // Create and set layout
122 | double p = TableLayout.PREFERRED;
123 | double f = TableLayout.FILL;
124 | double border = 10;
125 | double [] columnSize = {border, f, border};
126 | double [] rowSize = {border, border};
127 | layout = new TableLayout(columnSize, rowSize);
128 | container = frame.getContentPane();
129 | container.setLayout(layout);
130 |
131 | // Create controls
132 | JLabel labelType = new JLabel("Type of Address");
133 | comboType = new JComboBox(new String []
134 | {INTERNAL, DOMESTIC, INTERNATIONAL});
135 | comboType.setEditable(false);
136 | comboType.addActionListener(this);
137 | comboBuilding.setEditable(false);
138 | JButton buttonOK = new JButton("OK");
139 | JButton buttonCancel = new JButton("Cancel");
140 | JPanel panelButton = new JPanel();
141 | double p2 = buttonCancel.getPreferredSize().width;
142 | panelButton.setLayout(new TableLayout(new double [][] {{p2, 5, p2}, {p}}));
143 | panelButton.add(buttonOK, "0, 0");
144 | panelButton.add(buttonCancel, "2, 0");
145 |
146 | // Add controls
147 | addControl(labelType);
148 | addControl(comboType);
149 | addSpace();
150 | addControl(labelOffice);
151 | addControl(textOffice);
152 | addSpace();
153 | addControl(labelBuilding);
154 | addControl(comboBuilding);
155 | addSpace();
156 | addControl(labelStreet);
157 | addControl(textStreet);
158 | addSpace();
159 | addControl(labelCity);
160 | addControl(textCity);
161 | addSpace();
162 | addControl(labelState);
163 | addControl(textState);
164 | addSpace();
165 | addControl(labelZip);
166 | addControl(textZip);
167 | addSpace();
168 | addControl(labelProvidence);
169 | addControl(textProvidence);
170 | addSpace();
171 | addControl(labelCountry);
172 | addControl(textCountry);
173 | addSpace();
174 |
175 | // Add the button panel and then center justify it
176 | addControl(panelButton);
177 | TableLayoutConstraints tlc = layout.getConstraints(panelButton);
178 | tlc.hAlign = TableLayout.CENTER;
179 | layout.setConstraints(panelButton, tlc);
180 |
181 | // Add a filler row above the button panel so that the button panel
182 | // will stay at the bottom of the window
183 | layout.insertRow(tlc.row1, TableLayout.FILL);
184 |
185 | // Calculate the maximum size the frame would use
186 | int numItem = comboType.getItemCount();
187 | Dimension max = new Dimension(0, 0);
188 | frame.setVisible(true);
189 |
190 | for (int i = 0; i < numItem; i++)
191 | {
192 | comboType.setSelectedIndex(i);
193 | updateDynamicRows();
194 | Dimension d = frame.getPreferredSize();
195 | max.width = Math.max(max.width, d.width);
196 | max.height = Math.max(max.height, d.height);
197 | }
198 |
199 | comboType.setSelectedIndex(0);
200 | updateDynamicRows();
201 |
202 | // Show frame
203 | frame.setSize(max.width, max.height);
204 | frame.toFront();
205 | }
206 |
207 |
208 |
209 | /**
210 | * Adds a row and a control to the content pane.
211 | */
212 |
213 | private void addControl (Component component)
214 | {
215 | int rowNum = layout.getNumRow() - 1;
216 | layout.insertRow(rowNum, TableLayout.PREFERRED);
217 | container.add(component, new TableLayoutConstraints
218 | (1, rowNum, 1, rowNum, TableLayout.LEFT, TableLayout.BOTTOM));
219 | }
220 |
221 |
222 |
223 | /**
224 | * Adds a blank row so that the window looks nice.
225 | */
226 |
227 | private void addSpace()
228 | {
229 | int rowNum = layout.getNumRow() - 1;
230 | layout.insertRow(rowNum, EMPTY_SPACE);
231 | }
232 |
233 |
234 |
235 | /**
236 | * Invoked when the checkbox is toggled.
237 | */
238 |
239 | public void actionPerformed (ActionEvent e)
240 | {
241 | updateDynamicRows();
242 | }
243 |
244 |
245 |
246 | /**
247 | * Updates the visibility of dynamic rows. This method first zero outs all
248 | * dynamic rows. Then it resizes the relavent rows to
249 | * TableLayout.PREFERRED, thereby making their contents visible. Some
250 | * rows, like the ones pertaining to the city, are visible for more than
251 | * one type of address.
252 | */
253 |
254 | private void updateDynamicRows()
255 | {
256 | String type = "" + comboType.getSelectedItem();
257 | int rowMin, rowMax, rowStart = -1, rowStop = -1;
258 | rowMin = getRow(labelOffice);
259 | rowMax = getRow(textCountry);
260 |
261 | if (type.equals(INTERNAL))
262 | {
263 | rowStart = getRow(labelOffice);
264 | rowStop = getRow(comboBuilding);
265 | }
266 | else if (type.equals(DOMESTIC))
267 | {
268 | rowStart = getRow(labelStreet);
269 | rowStop = getRow(textZip);
270 | }
271 | else if (type.equals(INTERNATIONAL))
272 | {
273 | rowStart = getRow(labelProvidence);
274 | rowStop = getRow(textCountry);
275 | }
276 |
277 | if (rowMin >= 0 && rowMax >= 0)
278 | for (int y = rowMin; y <= rowMax; y++)
279 | layout.setRow(y, 0);
280 |
281 | if (rowStart >= 0 && rowStop >= 0)
282 | for (int y = rowStart; y <= rowStop + 1; y++)
283 | {
284 | double size = ((y - rowStart) % 3 == 2) ?
285 | EMPTY_SPACE : TableLayout.PREFERRED;
286 | layout.setRow(y, size);
287 | }
288 |
289 | if (type.equals(INTERNATIONAL))
290 | {
291 | rowStart = getRow(labelStreet);
292 | rowStop = getRow(textCity);
293 |
294 | if (rowStart >= 0 && rowStop >= 0)
295 | for (int y = rowStart; y <= rowStop + 1; y++)
296 | {
297 | double size = ((y - rowStart) % 3 == 2) ?
298 | EMPTY_SPACE : TableLayout.PREFERRED;
299 | layout.setRow(y, size);
300 | }
301 | }
302 |
303 | container.invalidate();
304 | container.validate();
305 | }
306 |
307 |
308 |
309 | /**
310 | * Gets the row associated with a control.
311 | *
312 | * @return the row in which a control has been placed or -1 if the component
313 | * is not found
314 | */
315 |
316 | private int getRow (Component component)
317 | {
318 | TableLayoutConstraints tlc = layout.getConstraints(component);
319 | return (tlc == null) ? -1 : tlc.row1;
320 | }
321 |
322 |
323 |
324 | }
325 |
--------------------------------------------------------------------------------
/www/articles/TableLayoutTutorialPart2/pages/hypercube.html:
--------------------------------------------------------------------------------
1 |
2 | Before drawing a hypercube, consider how to draw a cube.
8 | 
A cube is made up of six squares. Only two will be parallel to the 10 | xy axis. The other four would have to be imagined by two-dimensional 11 | people. Similarly, a hypercube is made up of eight cubes. Only two are 12 | parallel to the xyz space. The other six must be imagined by 13 | three-dimensional people.
14 |Let's draw the cube by first drawing two squares. Lets label each point in each square with a number from 1 to 4.
15 | 
Now connect each point in one square with the corresponding point in the other square.
17 | 18 | 19 |
Now you have a cube -- well, not 21 | exactly since the edges are not all equal. But it's easier to draw some 22 | of the edges elongated. So I'll do the same with the hypercube, thus 23 | I'll really draw a hyper rectangular prism. A hypercube looks almost 24 | the same, but its harder to see all the (3D) sides at once.
25 |A line is the area between two terminal points. A square is the area 26 | between to parallel lines. A cube is the area between two parallel 27 | squares. A hypercube is the area between two parallel cubes. So let's 28 | draw two parallel cubes and label the points o 29 | n each cube.
30 | 31 | 32 |
When we render a cube on a 35 | two-dimensional surface, we don't put the two parallel squares exactly 36 | parallel. We move one slightly up to provide prospective. For the same 37 | reason, let's move one of the cubes slightly up.
38 | 
Now let's connect the corresponding points in the two cubes.
40 | 41 | 42 |
These are all the edges in the 44 | hypercube. But it's too hard to visualize in black and white. So let's 45 | go back to the cubes. This time let's add color. A cube can be draw as 46 | four squares. Let's make each square a different color.
47 | 
You may have noticed that I've drawn each of the 12 edges twice. The 49 | edges that are part of more than two squares, I've drawn in both in 50 | both colors so that it is easy to see each square. However, they are 51 | the same edge.
52 |The sides of the cube are:
53 | 54 | 55 |front 56 | back 57 | left 58 | right 59 | top (dashed) 60 | bottom (dashed)61 | 62 |
Now let's draw the two cubes in different colors.
63 | 
In the hypercube, there will be eight sides:
65 | 66 |67 | front 68 | back 69 | left 70 | right 71 | top (dashed) 72 | bottom (dashed) 73 | x (dashed) 74 | y (dashed)75 |
I call the two new sides x and y 76 | for lack of a better name. Let's add the front and back sides of the 77 | hypercube. Remember that each side of a hypercube is a cube.
78 | 79 |
The magenta cube is parallel to the green cube. Both the magenta cube and the green cube are perpendicular to the blue cube. Yet, the blue cube shares one square face 81 | with the magenta cube and another square face with the green cube. 82 | In three dimensions, this would be an optical illusion, but in four dimensions it is a perfectly valid form.
83 | 84 |Remember that the front square of the magenta cube is just as close to us as the front square of the green cube. The blue cube is not tilted. It is parallel to the fourth axis.
85 | 86 |Now I've already drawn every edge 87 | in the hypercube -- some of them twice. However, I've only show four of 88 | the cubic faces of the hypercube. You might have noticed that there is 89 | no top or bottom. Let's add the top now.
90 | 91 | 92 |
The top side of the hypercube does 94 | not appear to be a cube. However, it is. Unfortunately, we are 95 | rendering the hypercube in two dimensions. The top side goes through 96 | the fourth axis like the front side, but the top side is parallel to 97 | the front side. Since we rendered the front side in a "nice" way, we're 98 | forced to render the top side in a "not so nice" way. The top side 99 | looks like a cube whose faces fell down to the left. However, this 100 | configuration allows the top side of the hypercube to be covered. The 101 | bottom side can be rendered in a similar fashion.
102 | 103 | 104 |
We 106 | still have to show side x and side y. These two sides will appear even 107 | more weird than the top and bottom sides. Cubic side x will connect the 108 | left square side of the magenta cube with the left square side of the green cube. Likewise, cubic side y will connect the right square side of magenta cube with the right square side of the green cube. To make these two cubic sides easy to see, let's draw only the left, right 109 | , FONT>x (dashed), and y (dashed) sides of the hypercube.
110 |Here's side x.
111 | 112 | 113 |
Here's both side x and side y.
115 | 
Finally, here's the hypercube in all of its glory.
117 | 118 | 119 |
That's 121 | eight cubes, twenty squares, thirty two edges, and sixteen terminal 122 | points. Here it is again with the redundant rendering of edges removed. 123 | Can you still see all eight cubes?
124 | 125 |
Well, 127 | to be a true hypercube, all edges would have to be the same length. For 128 | clarity, I discarded this fact. But the true hypercube would actually 129 | look like this.
130 | 131 |
Let's find the eight cubes in the hypercube.
133 | 134 |
If 136 | we wanted to, we could try drawing a hyper-hypercube, a five 137 | dimensional figure. However, rendering a five dimensional figure in two 138 | dimensions is very messy. It would be better to render a 139 | hyper-hypercube in three dimensions.
140 | 141 |12 | The following are quotes from software engineers who have used TableLayout and provided unsolicited 13 | feedback. To protect the privacy of the individuals, their email address and names are not given. 14 | For brevity, some quotes represents only part of a letter. 15 |
16 | 17 |18 | 19 | The opinions given here do not represent endorsement from any company or organizations that own the domain 20 | names shown below. The opinions were expressed by individual software developers whose email addresses 21 | were from the domains shown. 22 |
23 | 24 || From: | 27 |yahoo.com | 28 |29 | | |
| 33 | | 34 | Great job on the layout! I love it. I am blown away how easy it is to use. It is 35 | by far much better than any of the other layouts. The only one I will use is CardLayout for a wizard 36 | component I wrote. But other than that, this is now my only layout I use! I think you should seriously 37 | consider submitting it to Sun to get included in the next version of Java, if not a 1.4 update, maybe 1.5. 38 | It is, as you showed, much easier to use than both GridLayout and GridBagLayout. 39 | | 40 |||
| From: | 45 | 46 |infosim.com | 47 |48 | | |
| 51 | | 52 | ...this should most definitely be in the JDK - it blows away the 53 | competition (have you tried to actually use the SpringLayout). 54 | | 55 |||
| From: | 61 |ota.fr.socgen.com | 62 |63 | | |
| 67 | | 68 | Your TableLayout saves us a lot of time and handles gracefully the most complex 69 | designs, great work! 70 | | 71 |||
| From: | 76 | 77 |lane15.com | 78 |79 | | |
| 82 | | 83 | I really love your TableLayout. I think it's going to revolutionize layout in Java GUIs. 84 | | 85 |||
| From: | 91 |wpafb.af.mil | 92 |93 | | |
| 97 | | 98 | Liked the article, it really opened my eyes to AWT. I've been so immersed 99 | in Swing, that I didn't realize AWT could have the flexibility demonstrated 100 | in your article. 101 | | 102 |||
| From: | 107 | 108 |absolutesys.com | 109 |110 | | |
| 113 | |
114 | I read your article "TableLayout - An Alternative to GridBagLayout" on the
115 | Sun JFC site, and I think TableLayout is quite superb. 116 | 117 | I use Netbeans for most of my work, and I am now trying to find a Netbeans 118 | support module for TableLayout. 119 | |
120 |
121 | ||
| From: | 126 |clarityconnect.com | 127 |128 | | |
| 132 | | 133 | I wanted to personally thank you for the excellent TableLayout. 134 | It is exactly in the sweet spot between simplicity and power. 135 | Before TableLayout I was layering panels in BorderLayouts like you 136 | wouldn't believe! I had to write the UIs in one sitting because I could 137 | never go back and make a change! 138 | I tried creating UIs with every release of JBuilder from latte to version 139 | 6. Every time I went back to SlickEdit (although I've now switched to 140 | IntelliJ Idea) 141 | And I tried coding GridBagLayout by hand. That didn't even come out 142 | looking like the the Java I know. 143 | So, I just stayed away from writing UI code. 144 | Finally, with TableLayout, I can sculpt the UI as I go along. 145 | | 146 |||
| From: | 151 | 152 |offset.demon.nl | 153 |154 | | |
| 157 | |
158 | My compliments on your article about table layout and the code, found on
159 | the Swing connection. 160 | 161 | A longtime 'command line' DOS programmer, I am trying to teach myself Java 162 | which I admire greatly but find GUI coding terrible. I quickly found out 163 | how to use this layout and have already used it in an in house application. 164 | I hope the Swing team will integrate this in their next offering. 165 | No reply required -- just thanks for your work. 166 | |
167 |
168 | ||
| From: | 173 |shef.ac.uk | 174 |175 | | |
| 179 | | 180 | Just wanted to thank you for your article on TSC on the new TableLayout, 181 | it was exactly what I needed for a project I'm doing (sports scorer for 182 | Cricket). Great article 183 | | 184 |||
| From: | 189 | 190 |askasicomp.com | 191 |192 | | |
| 195 | | 196 | I have been sidetracked for a while, but I finally took 197 | the time to read your article: 198 | TableLayout - An Alternative to GridBagLayout A Simple and Powerful Layout Manager 199 | I just have to make more time to play with stuff like this. 200 | This is way cool. Although I'm not qualified to say this, 201 | I am way impressed. Keep up the great work!!! 202 | | 203 |||
| From: | 209 |pacbell.net | 210 |211 | | |
| 215 | |
216 | I just can't resist to thank you for your excellent job on the TableLayout.
217 | It is the best layout to date. Lots of people literally suffering working
218 | with Sun's layouts, these layouts are a real pain. 219 | 220 | Your layout is a joy to work with! 221 | |
222 | ||
| From: | 228 |aciworldwide.com | 229 |230 | | |
| 233 | | 234 | I read your article about your TableLayout manager that is posted on the 235 | Sun web site. I want to tell you that I think your layout manager is the 236 | easiest to use of all of the layout manager classes that I have 237 | implemented. I have primarily been working with the GridBagLayout manager 238 | for all of my Swing projects. It was very frustrating trying to get the 239 | UIs to size without any of the pixel problems that you point out in your 240 | article. Thanks again for such a great layout manager class. 241 | | 242 | 243 |||
| From: | 248 |mac.com | 249 |250 | | |
| 254 | | 255 | TableLayout is fantastic! Are you planning any enhancements? 256 | | 257 |||
| From: | 262 | 263 |mueller.ca | 264 |265 | | |
| 268 | | 269 | TableLayout is very useful and makes it a lot easier to develop Swing 270 | applications. In fact, the existing knowledge on spreadsheets and HTML 271 | tables enables developers to create frames and dialogs much more 272 | efficiently. Thanks for this excellent invention! 273 | | 274 |||
| From: | 280 |powervision.com | 281 |282 | | |
| 286 | | 287 | I wanted to say thanks for the layout! As many of the other quotes from 288 | your web-site attest, it's a great contribution. I don't abhor laying out 289 | my GUI screens anymore, I just sketch them on paper and lay them out in 290 | seconds. 291 | | 292 |||
| From: | 297 | 298 |rlx.com | 299 |300 | | |
| 303 | | 304 | TableLayout is a terrific layout manager. Thank you for the excellent work. 305 | | 306 |||
| From: | 312 |JGoodies.com | 313 |314 | | |
| 318 | | 319 | You have significantly improved the layout situation in Swing applications. 320 | It is not only that you've inspired me, but I have used your TableLayout in 321 | Swing courses and have found that its mental model is what developers can 322 | understand quickly. 323 | | 324 |||
328 | Back to project home 329 |
330 | 331 | 332 | --------------------------------------------------------------------------------