PageRenderTime 65ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/prototypes/miglayout/net/miginfocom/demo/SwingDemo.java

http://github.com/graemeg/fpGUI
Java | 3668 lines | 3124 code | 425 blank | 119 comment | 191 complexity | a3f71b91768df5843694793296603017 MD5 | raw file
Possible License(s): LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. package net.miginfocom.demo;
  2. import net.miginfocom.layout.*;
  3. import net.miginfocom.swing.MigLayout;
  4. import javax.swing.*;
  5. import javax.swing.border.EmptyBorder;
  6. import javax.swing.border.EtchedBorder;
  7. import javax.swing.border.LineBorder;
  8. import javax.swing.event.ListSelectionEvent;
  9. import javax.swing.event.ListSelectionListener;
  10. import java.awt.*;
  11. import java.awt.event.*;
  12. import java.io.FileWriter;
  13. import java.io.IOException;
  14. import java.io.PrintWriter;
  15. import java.io.StringWriter;
  16. import java.util.Random;
  17. /*
  18. * License (BSD):
  19. * ==============
  20. *
  21. * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
  22. * All rights reserved.
  23. *
  24. * Redistribution and use in source and binary forms, with or without modification,
  25. * are permitted provided that the following conditions are met:
  26. * Redistributions of source code must retain the above copyright notice, this list
  27. * of conditions and the following disclaimer.
  28. * Redistributions in binary form must reproduce the above copyright notice, this
  29. * list of conditions and the following disclaimer in the documentation and/or other
  30. * materials provided with the distribution.
  31. * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
  32. * used to endorse or promote products derived from this software without specific
  33. * prior written permission.
  34. *
  35. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  36. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  37. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  38. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  39. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  40. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  41. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  42. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  43. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  44. * OF SUCH DAMAGE.
  45. *
  46. * @version 1.0
  47. * @author Mikael Grev, MiG InfoCom AB
  48. * Date: 2006-sep-08
  49. */
  50. public class SwingDemo extends JFrame
  51. {
  52. public static final int INITIAL_INDEX = 0;
  53. private static final boolean DEBUG = false;
  54. private static final boolean OPAQUE = false;
  55. private static final String[][] panels = new String[][] {
  56. // {"Test", "Test, disregard"},
  57. {"Welcome", "\n\n \"MigLayout makes complex layouts easy and normal layouts one-liners.\""},
  58. {"Quick Start", "This is an example of how to build a common dialog type. Note that there are no special components, nested panels or absolute references to cell positions. If you look at the source code you will see that the layout code is very simple to understand."},
  59. {"Plain", "A simple example on how simple it is to create normal forms. No builders needed since the whole layout manager works like a builder."},
  60. {"Alignments", "Shows how the alignment of components are specified. At the top/left is the alignment for the column/row. The components have no alignments specified.\n\nNote that baseline alignment will be interpreted as 'center' before JDK 6."},
  61. {"Cell Alignments", "Shows how components are aligned when both column/row alignments and component constraints are specified. At the top/left are the alignment for the column/row and the text on the buttons is the component constraint that will override the column/row alignment if it is an alignment.\n\nNote that baseline alignment will be interpreted as 'center' before JDK 6."},
  62. {"Basic Sizes", "A simple example that shows how to use the column or row min/preferred/max size to set the sizes of the contained components and also an example that shows how to do this directly in the component constraints."},
  63. {"Growing", "A simple example that shows how to use the growx and growy constraint to set the sizes and how they should grow to fit the available size. Both the column/row and the component grow/shrink constraints can be set, but the components will always be confined to the space given by its column/row."},
  64. {"Grow Shrink", "Demonstrates the very flexible grow and shrink constraints that can be set on a component.\nComponents can be divided into grow/shrink groups and also have grow/shrink weight within each of those groups.\n\nBy default " +
  65. "components shrink to their inherent (or specified) minimum size, but they don't grow."},
  66. {"Span", "This example shows the powerful spanning and splitting that can be specified in the component constraints. With spanning any number of cells can be merged with the additional option to split that space for more than one component. This makes layouts very flexible and reduces the number of times you will need nested panels to very few."},
  67. {"Flow Direction", "Shows the different flow directions. Flow direction for the layout specifies if the next cell will be in the x or y dimension. Note that it can be a different flow direction in the slit cell (the middle cell is slit in two). Wrap is set to 3 for all panels."},
  68. {"Grouping", "Sizes for both components and columns/rows can be grouped so they get the same size. For instance buttons in a button bar can be given a size-group so that they will all get " +
  69. "the same minimum and preferred size (the largest within the group). Size-groups can be set for the width, height or both."},
  70. {"Units", "Demonstrates the basic units that are understood by MigLayout. These units can be extended by the user by adding one or more UnitConverter(s)."},
  71. {"Component Sizes", "Minimum, preferred and maximum component sizes can be overridden in the component constraints using any unit type. The format to do this is short and simple to understand. You simply specify the " +
  72. "min, preferred and max sizes with a colon between.\n\nAbove are some examples of this. An exclamation mark means that the value will be used for all sizes."},
  73. {"Bound Sizes", "Shows how to create columns that are stable between tabs using minimum sizes."},
  74. {"Cell Position", "Even though MigLayout has automatic grid flow you can still specify the cell position explicitly. You can even combine absolute (x, y) and flow (skip, wrap and newline) constraints to build your layout."},
  75. {"Orientation", "MigLayout supports not only right-to-left orientation, but also bottom-to-top. You can even set the flow direction so that the flow is vertical instead of horizontal. It will automatically " +
  76. "pick up if right-to-left is to be used depending on the ComponentWrapper, but it can also be manually set for every layout."},
  77. {"Absolute Position", "Demonstrates the option to place any number of components using absolute coordinates. This can be just the position (if min/preferred size) using \"x y p p\" format or" +
  78. "the bounds using the \"x1 y1 x2 y2\" format. Any unit can be used and percent is relative to the parent.\nAbsolute components will not disturb the flow or occupy cells in the grid. " +
  79. "Absolute positioned components will be taken into account when calculating the container's preferred size."},
  80. {"Component Links", "Components can be linked to any side of any other component. It can be a forward, backward or cyclic link references, as long as it is stable and won't continue to change value over many iterations." +
  81. "Links are referencing the ID of another component. The ID can be overridden by the component's constrains or is provided by the ComponentWrapper. For instance it will use the component's 'name' on Swing.\n" +
  82. "Since the links can be combined with any expression (such as 'butt1.x+10' or 'max(button.x, 200)' the links are very customizable."},
  83. {"Docking", "Docking components can be added around the grid. The docked component will get the whole width/height on the docked side by default, however this can be overridden. When all docked components are laid out, whatever space " +
  84. "is left will be available for the normal grid laid out components. Docked components does not in any way affect the flow in the grid.\n\nSince the docking runs in the same code path " +
  85. "as the normal layout code the same properties can be specified for the docking components. You can for instance set the sizes and alignment or link other components to their docked component's bounds."},
  86. {"Button Bars", "Button order is very customizable and are by default different on the supported platforms. E.g. Gaps, button order and minimum button size are properties that are 'per platform'. MigLayout picks up the current platform automatically and adjusts the button order and minimum button size accordingly, all without using a button builder or any other special code construct."},
  87. {"Visual Bounds", "Human perceptible bounds may not be the same as the mathematical bounds for the component. This is for instance the case if there is a drop shadow painted by the component's border. MigLayout can compensate " +
  88. "for this in a simple way. Note the top middle tab-component, it is not aligned visually correct on Windows XP. For the second tab the bounds are corrected automatically on Windows XP."},
  89. {"Debug", "Demonstrates the non-intrusive way to get visual debugging aid. There is no need to use a special DebugPanel or anything that will need code changes. The user can simply turn on debug on the layout manager by using the \"debug\" constraint and it will " +
  90. "continuously repaint the panel with debug information on top. This means you don't have to change your code to debug!"},
  91. {"Layout Showdown", "This is an implementation of the Layout Showdown posted on java.net by John O'Conner. The first tab is a pure implemenetation of the showdown that follows all the rules. The second tab is a slightly fixed version that follows some improved layout guidelines." +
  92. "The source code is for bothe the first and for the fixed version. Note the simplification of the code for the fixed version. Writing better layouts with MiG Layout is reasier that writing bad.\n\nReference: http://weblogs.java.net/blog/joconner/archive/2006/10/more_informatio.html"},
  93. {"API Constraints1", "This dialog shows the constraint API added to v2.0. It works the same way as the string constraints but with chained method calls. See the source code for details."},
  94. {"API Constraints2", "This dialog shows the constraint API added to v2.0. It works the same way as the string constraints but with chained method calls. See the source code for details."}
  95. };
  96. private int lastIndex = -10;
  97. private JPanel contentPanel = DEBUG ? new JPanel(new BorderLayout()) : new JPanel(new MigLayout("wrap", "[]unrel[grow]", "[grow][pref]"));
  98. private JTabbedPane layoutPickerTabPane = new JTabbedPane();
  99. private JList pickerList = new JList(new DefaultListModel());
  100. private JTabbedPane southTabPane = new JTabbedPane();
  101. private JScrollPane descrTextAreaScroll = createTextAreaScroll("", 5, 80, true);
  102. private JTextArea descrTextArea = (JTextArea) descrTextAreaScroll.getViewport().getView();
  103. private JScrollPane sourceTextAreaScroll = null;
  104. private JTextArea sourceTextArea = null;
  105. private JPanel layoutDisplayPanel = new JPanel(new BorderLayout(0, 0));
  106. private static boolean buttonOpaque = true;
  107. private JFrame sourceFrame = null;
  108. private JTextArea sourceFrameTextArea = null;
  109. private static int benchRuns = 0;
  110. private static long startupMillis = 0;
  111. private static long timeToShowMillis = 0;
  112. private static long benchRunTime = 0;
  113. private static String benchOutFileName = null;
  114. private static boolean append = false;
  115. private static long lastRunTimeStart = 0;
  116. private static StringBuffer runTimeSB = null;
  117. public static void main(String args[])
  118. {
  119. try {
  120. System.setProperty("apple.laf.useScreenMenuBar", "true");
  121. System.setProperty("com.apple.mrj.application.apple.menu.about.name", "MiGLayout Swing Demo");
  122. } catch(Throwable ex) {
  123. // Beacuse we did not have permissions.
  124. }
  125. startupMillis = System.currentTimeMillis();
  126. String laf = UIManager.getSystemLookAndFeelClassName();
  127. if (args.length > 0) {
  128. for (int i = 0; i <args.length; i++) {
  129. String arg = args[i].trim();
  130. if (arg.startsWith("-laf")) {
  131. laf = arg.substring(4);
  132. } else if (arg.startsWith("-bench")) {
  133. benchRuns = 10;
  134. try {
  135. benchRuns = Integer.parseInt(arg.substring(6));
  136. } catch(Exception ex) {}
  137. } else if (arg.startsWith("-bout")) {
  138. benchOutFileName = arg.substring(5);
  139. } else if (arg.startsWith("-append")) {
  140. append = true;
  141. } else if (arg.startsWith("-verbose")) {
  142. runTimeSB = new StringBuffer(256);
  143. } else if (arg.equals("-steel")) {
  144. laf = "javax.swing.plaf.metal.MetalLookAndFeel";
  145. System.setProperty("swing.metalTheme", "steel");
  146. } else if (arg.equals("-ocean")) {
  147. laf = "javax.swing.plaf.metal.MetalLookAndFeel";
  148. } else {
  149. System.out.println("Usage: [-laf[look_&_feel_class_name]] [-bench[#_of_runs]] [-bout[benchmark_results_filename]] [-append] [-steel] [-ocean]\n" +
  150. " -laf Set the Application Look&Feel. (Look and feel must be in Classpath)\n" +
  151. " -bench Run demo as benchmark. Run count can be appended. 10 is default.\n" +
  152. " -bout Benchmark results output filename.\n" +
  153. " -append Appends the result to the -bout file.\n" +
  154. " -verbose Print the times of every run.\n" +
  155. " -steel Sets the old Steel theme for Sun's Metal look&feel.\n" +
  156. " -ocean Sets the Ocean theme for Sun's Metal look&feel.\n" +
  157. "\nExamples:\n" +
  158. " java -jar swingdemoapp.jar -bench -boutC:/bench.txt -append\n" +
  159. " java -jar swingdemoapp.jar -ocean -bench20\n" +
  160. " java -cp c:\\looks-2.0.4.jar;.\\swingdemoapp.jar net.miginfocom.demo.SwingDemo -lafcom.jgoodies.looks.plastic.PlasticLookAndFeel -bench20 -boutC:/bench.txt");
  161. System.exit(0);
  162. }
  163. }
  164. }
  165. if (benchRuns > 0)
  166. LayoutUtil.setDesignTime(null, true); // So that the string constraints to create the UnitValues is saved and can be recreated exactly.
  167. // laf = "net.sourceforge.napkinlaf.NapkinLookAndFeel";
  168. // laf = "javax.swing.plaf.metal.MetalLookAndFeel";
  169. // System.setProperty("swing.metalTheme", "steel");
  170. // laf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
  171. // laf = "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel";
  172. // laf = "com.jgoodies.looks.plastic.PlasticLookAndFeel";
  173. // laf = "com.jgoodies.looks.plastic.Plastic3DLookAndFeel";
  174. // laf = "com.jgoodies.looks.plastic.PlasticXPLookAndFeel";
  175. // laf = "com.jgoodies.looks.windows.WindowsLookAndFeel";
  176. if (laf.endsWith("WindowsLookAndFeel"))
  177. buttonOpaque = false;
  178. final String laff = laf;
  179. SwingUtilities.invokeLater(new Runnable() {
  180. public void run() {
  181. try {
  182. UIManager.setLookAndFeel(laff);
  183. } catch (Exception ex) {
  184. ex.printStackTrace();
  185. }
  186. SwingDemo demo = new SwingDemo();
  187. }
  188. });
  189. }
  190. public SwingDemo()
  191. {
  192. super("MigLayout Swing Demo v2.4 - Mig Layout v" + LayoutUtil.getVersion());
  193. // if (benchRuns > 0)
  194. // RepaintManager.currentManager(this).setDoubleBufferingEnabled(false);
  195. if (benchRuns == 0) {
  196. sourceTextAreaScroll = createTextAreaScroll("", 5, 80, true);
  197. sourceTextArea = (JTextArea) sourceTextAreaScroll.getViewport().getView();
  198. }
  199. if (DEBUG) {
  200. contentPanel.add(layoutDisplayPanel, BorderLayout.CENTER);
  201. // contentPanel.add(layoutPickerTabPane, BorderLayout.WEST);
  202. // contentPanel.add(descriptionTabPane, BorderLayout.SOUTH);
  203. } else {
  204. contentPanel.add(layoutPickerTabPane, "spany,grow");
  205. contentPanel.add(layoutDisplayPanel, "grow");
  206. contentPanel.add(southTabPane, "growx");
  207. }
  208. setContentPane(contentPanel);
  209. pickerList.setOpaque(OPAQUE);
  210. ((DefaultListCellRenderer) pickerList.getCellRenderer()).setOpaque(OPAQUE);
  211. pickerList.setSelectionForeground(new Color(0, 0, 220));
  212. pickerList.setBackground(null);
  213. pickerList.setBorder(new EmptyBorder(2, 5, 0, 4));
  214. pickerList.setFont(pickerList.getFont().deriveFont(Font.BOLD));
  215. layoutPickerTabPane.addTab("Example Browser", pickerList);
  216. descrTextAreaScroll.setBorder(null);
  217. descrTextAreaScroll.setOpaque(OPAQUE);
  218. descrTextAreaScroll.getViewport().setOpaque(OPAQUE);
  219. descrTextArea.setOpaque(OPAQUE);
  220. descrTextArea.setEditable(false);
  221. descrTextArea.setBorder(new EmptyBorder(0, 4, 0, 4));
  222. southTabPane.addTab("Description", descrTextAreaScroll);
  223. if (sourceTextArea != null) {
  224. sourceTextAreaScroll.setBorder(null);
  225. sourceTextAreaScroll.setOpaque(OPAQUE);
  226. sourceTextAreaScroll.getViewport().setOpaque(OPAQUE);
  227. sourceTextAreaScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  228. sourceTextArea.setOpaque(OPAQUE);
  229. sourceTextArea.setLineWrap(false);
  230. sourceTextArea.setWrapStyleWord(false);
  231. sourceTextArea.setEditable(false);
  232. sourceTextArea.setBorder(new EmptyBorder(0, 4, 0, 4));
  233. sourceTextArea.setFont(new Font("monospaced", Font.PLAIN, 11));
  234. southTabPane.addTab("Source Code", sourceTextAreaScroll);
  235. southTabPane.addMouseListener(new MouseAdapter() {
  236. public void mouseClicked(MouseEvent e)
  237. {
  238. if (e.getClickCount() == 2)
  239. showSourceInFrame();
  240. }
  241. });
  242. }
  243. for (int i = 0; i < panels.length; i++)
  244. ((DefaultListModel) pickerList.getModel()).addElement(panels[i][0]);
  245. try {
  246. setSize(900, 650);
  247. setLocationRelativeTo(null);
  248. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  249. setVisible(true);
  250. } catch(Throwable t) {
  251. t.printStackTrace();
  252. System.exit(1);
  253. }
  254. pickerList.addListSelectionListener(new ListSelectionListener() {
  255. public void valueChanged(ListSelectionEvent e)
  256. {
  257. int ix = pickerList.getSelectedIndex();
  258. if (ix == -1 || lastIndex == ix)
  259. return;
  260. lastIndex = ix;
  261. String methodName = "create" + panels[ix][0].replace(' ', '_');
  262. layoutDisplayPanel.removeAll();
  263. try {
  264. pickerList.requestFocusInWindow();
  265. final JComponent panel = (JComponent) SwingDemo.class.getMethod(methodName, new Class[0]).invoke(SwingDemo.this, new Object[0]);
  266. layoutDisplayPanel.add(panel);
  267. descrTextArea.setText(panels[ix][1]);
  268. descrTextArea.setCaretPosition(0);
  269. contentPanel.revalidate();
  270. } catch (Exception e1) {
  271. e1.printStackTrace(); // Should never happpen...
  272. }
  273. southTabPane.setSelectedIndex(0);
  274. }
  275. });
  276. pickerList.requestFocusInWindow();
  277. Toolkit.getDefaultToolkit().setDynamicLayout(true);
  278. if (benchRuns > 0) {
  279. doBenchmark();
  280. } else {
  281. pickerList.setSelectedIndex(INITIAL_INDEX);
  282. KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
  283. public boolean dispatchKeyEvent(KeyEvent e)
  284. {
  285. if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_B && (e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) > 0) {
  286. startupMillis = System.currentTimeMillis();
  287. timeToShowMillis = System.currentTimeMillis() - startupMillis;
  288. benchRuns = 1;
  289. doBenchmark();
  290. return true;
  291. }
  292. return false;
  293. }
  294. });
  295. }
  296. }
  297. private void doBenchmark()
  298. {
  299. Thread benchThread = new Thread() {
  300. public void run()
  301. {
  302. for (int j = 0; j < benchRuns; j++) {
  303. lastRunTimeStart = System.currentTimeMillis();
  304. for (int i = 0, iCnt = pickerList.getModel().getSize(); i < iCnt; i++) {
  305. if (benchRuns > 0 && panels[i][0].equals("Visual Bounds"))
  306. continue; // the SWT version does not have Visual bounds...
  307. final int ii = i;
  308. try {
  309. SwingUtilities.invokeAndWait(new Runnable() {
  310. public void run() {
  311. pickerList.setSelectedIndex(ii);
  312. Toolkit.getDefaultToolkit().sync();
  313. }
  314. });
  315. } catch (Exception e) {
  316. e.printStackTrace();
  317. }
  318. Component[] comps = layoutDisplayPanel.getComponents();
  319. for (int cIx = 0; cIx < comps.length; cIx++) {
  320. if (comps[cIx] instanceof JTabbedPane) {
  321. final JTabbedPane tp = (JTabbedPane) comps[cIx];
  322. for (int k = 0, kCnt = tp.getTabCount(); k < kCnt; k++) {
  323. final int kk = k;
  324. try {
  325. SwingUtilities.invokeAndWait(new Runnable() {
  326. public void run() {
  327. tp.setSelectedIndex(kk);
  328. Toolkit.getDefaultToolkit().sync();
  329. if (timeToShowMillis == 0)
  330. timeToShowMillis = System.currentTimeMillis() - startupMillis;
  331. }
  332. });
  333. } catch (Exception e) {
  334. e.printStackTrace();
  335. }
  336. }
  337. }
  338. }
  339. }
  340. if (runTimeSB != null) {
  341. runTimeSB.append("Run ").append(j).append(": ");
  342. runTimeSB.append(System.currentTimeMillis() - lastRunTimeStart).append(" millis.\n");
  343. }
  344. }
  345. benchRunTime = System.currentTimeMillis() - startupMillis - timeToShowMillis;
  346. final String message = "Java Version: " + System.getProperty("java.version") + "\n" +
  347. "Look & Feel: " + UIManager.getLookAndFeel().getDescription() + "\n" +
  348. "Time to Show: " + timeToShowMillis + " millis.\n" +
  349. (runTimeSB != null ? runTimeSB.toString() : "") +
  350. "Benchmark Run Time: " + benchRunTime + " millis.\n" +
  351. "Average Run Time: " + (benchRunTime / benchRuns) + " millis (" + benchRuns + " runs).\n\n";
  352. if (benchOutFileName == null) {
  353. JOptionPane.showMessageDialog(SwingDemo.this, message, "Results", JOptionPane.INFORMATION_MESSAGE);
  354. } else {
  355. FileWriter fw = null;
  356. try {
  357. fw = new FileWriter(benchOutFileName, append);
  358. fw.write(message);
  359. } catch(IOException ex) {
  360. ex.printStackTrace();
  361. } finally {
  362. if (fw != null)
  363. try {fw.close();} catch(IOException ex) {}
  364. }
  365. }
  366. System.out.println(message);
  367. }
  368. };
  369. benchThread.start();
  370. }
  371. private void setSource(String source)
  372. {
  373. if (benchRuns > 0 || sourceTextArea == null)
  374. return;
  375. if (source.length() > 0) {
  376. source = source.replaceAll("\t\t", "");
  377. source = "DOUBLE CLICK TAB TO SHOW SOURCE IN SEPARATE WINDOW!\n===================================================\n\n" + source;
  378. }
  379. sourceTextArea.setText(source);
  380. sourceTextArea.setCaretPosition(0);
  381. if (sourceFrame != null && sourceFrame.isVisible()) {
  382. sourceFrameTextArea.setText(source.length() > 105 ? source.substring(105) : "No Source Code Available!");
  383. sourceFrameTextArea.setCaretPosition(0);
  384. }
  385. }
  386. private void showSourceInFrame()
  387. {
  388. if (sourceTextArea == null)
  389. return;
  390. JScrollPane sourceFrameTextAreaScroll = createTextAreaScroll("", 5, 80, true);
  391. sourceFrameTextArea = (JTextArea) sourceFrameTextAreaScroll.getViewport().getView();
  392. sourceFrameTextAreaScroll.setBorder(null);
  393. sourceFrameTextAreaScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  394. sourceFrameTextArea.setLineWrap(false);
  395. sourceFrameTextArea.setWrapStyleWord(false);
  396. sourceFrameTextArea.setEditable(false);
  397. sourceFrameTextArea.setBorder(new EmptyBorder(10, 10, 10, 10));
  398. sourceFrameTextArea.setFont(new Font("monospaced", Font.PLAIN, 12));
  399. String source = this.sourceTextArea.getText();
  400. sourceFrameTextArea.setText(source.length() > 105 ? source.substring(105) : "No Source Code Available!");
  401. sourceFrameTextArea.setCaretPosition(0);
  402. sourceFrame = new JFrame("Source Code");
  403. sourceFrame.getContentPane().add(sourceFrameTextAreaScroll, BorderLayout.CENTER);
  404. sourceFrame.setSize(700, 800);
  405. sourceFrame.setLocationRelativeTo(this);
  406. sourceFrame.setVisible(true);
  407. }
  408. public JComponent createTest()
  409. {
  410. JComponent pane = new JPanel();
  411. pane.setLayout(new MigLayout("debug"));
  412. pane.add(new JLabel("Separator"), "gapbottom 1, ax r, spanx, split");
  413. pane.add(new JSeparator(), "gap rel, growx");
  414. JLabel label = new JLabel("<html><font color=red><b>some text in label</b></font></html>");
  415. pane.add(label, "wrap");
  416. pane.add(new JButton("Button1"));
  417. pane.add(new JButton("Button2"));
  418. pane.add(new JButton("Button3"));
  419. return pane;
  420. }
  421. public JComponent createAPI_Constraints1()
  422. {
  423. JTabbedPane tabbedPane = new JTabbedPane();
  424. LC layC = new LC().fill().wrap();
  425. AC colC = new AC().align("right", 1).fill(2, 4).grow(100, 2, 4).align("right", 3).gap("15", 2);
  426. AC rowC = new AC().align("top", 7).gap("15!", 6).grow(100, 8);
  427. JPanel panel = createTabPanel(new MigLayout(layC, colC, rowC)); // Makes the background gradient
  428. // References to text fields not stored to reduce code clutter.
  429. JScrollPane list2 = new JScrollPane(new JList(new String[] {"Mouse, Mickey"}));
  430. panel.add(list2, new CC().spanY().growY().minWidth("150").gapX(null, "10"));
  431. panel.add(new JLabel("Last Name"));
  432. panel.add(new JTextField());
  433. panel.add(new JLabel("First Name"));
  434. panel.add(new JTextField(), new CC().wrap().alignX("right"));
  435. panel.add(new JLabel("Phone"));
  436. panel.add(new JTextField());
  437. panel.add(new JLabel("Email"));
  438. panel.add(new JTextField());
  439. panel.add(new JLabel("Address 1"));
  440. panel.add(new JTextField(), new CC().spanX().growX());
  441. panel.add(new JLabel("Address 2"));
  442. panel.add(new JTextField(), new CC().spanX().growX());
  443. panel.add(new JLabel("City"));
  444. panel.add(new JTextField(), new CC().wrap());
  445. panel.add(new JLabel("State"));
  446. panel.add(new JTextField());
  447. panel.add(new JLabel("Postal Code"));
  448. panel.add(new JTextField(10), new CC().spanX(2).growX(0));
  449. panel.add(new JLabel("Country"));
  450. panel.add(new JTextField(), new CC().wrap());
  451. panel.add(new JButton("New"), new CC().spanX(5).split(5).tag("other"));
  452. panel.add(new JButton("Delete"), new CC().tag("other"));
  453. panel.add(new JButton("Edit"), new CC().tag("other"));
  454. panel.add(new JButton("Save"), new CC().tag("other"));
  455. panel.add(new JButton("Cancel"), new CC().tag("cancel"));
  456. tabbedPane.addTab("Layout Showdown (improved)", panel);
  457. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  458. "\n" +
  459. "LC layC = new LC().fill().wrap();\n" +
  460. "AC colC = new AC().align(\"right\", 1).fill(2, 4).grow(100, 2, 4).align(\"right\", 3).gap(\"15\", 2);\n" +
  461. "AC rowC = new AC().align(\"top\", 7).gap(\"15!\", 6).grow(100, 8);\n" +
  462. "\n" +
  463. "JPanel panel = createTabPanel(new MigLayout(layC, colC, rowC)); // Makes the background gradient\n" +
  464. "\n" +
  465. "// References to text fields not stored to reduce code clutter.\n" +
  466. "\n" +
  467. "JScrollPane list2 = new JScrollPane(new JList(new String[] {\"Mouse, Mickey\"}));\n" +
  468. "panel.add(list2, new CC().spanY().growY().minWidth(\"150\").gapX(null, \"10\"));\n" +
  469. "\n" +
  470. "panel.add(new JLabel(\"Last Name\"));\n" +
  471. "panel.add(new JTextField());\n" +
  472. "panel.add(new JLabel(\"First Name\"));\n" +
  473. "panel.add(new JTextField(), new CC().wrap().alignX(\"right\"));\n" +
  474. "panel.add(new JLabel(\"Phone\"));\n" +
  475. "panel.add(new JTextField());\n" +
  476. "panel.add(new JLabel(\"Email\"));\n" +
  477. "panel.add(new JTextField());\n" +
  478. "panel.add(new JLabel(\"Address 1\"));\n" +
  479. "panel.add(new JTextField(), new CC().spanX().growX());\n" +
  480. "panel.add(new JLabel(\"Address 2\"));\n" +
  481. "panel.add(new JTextField(), new CC().spanX().growX());\n" +
  482. "panel.add(new JLabel(\"City\"));\n" +
  483. "panel.add(new JTextField(), new CC().wrap());\n" +
  484. "panel.add(new JLabel(\"State\"));\n" +
  485. "panel.add(new JTextField());\n" +
  486. "panel.add(new JLabel(\"Postal Code\"));\n" +
  487. "panel.add(new JTextField(10), new CC().spanX(2).growX(0));\n" +
  488. "panel.add(new JLabel(\"Country\"));\n" +
  489. "panel.add(new JTextField(), new CC().wrap());\n" +
  490. "\n" +
  491. "panel.add(new JButton(\"New\"), new CC().spanX(5).split(5).tag(\"other\"));\n" +
  492. "panel.add(new JButton(\"Delete\"), new CC().tag(\"other\"));\n" +
  493. "panel.add(new JButton(\"Edit\"), new CC().tag(\"other\"));\n" +
  494. "panel.add(new JButton(\"Save\"), new CC().tag(\"other\"));\n" +
  495. "panel.add(new JButton(\"Cancel\"), new CC().tag(\"cancel\"));\n" +
  496. "\n" +
  497. "tabbedPane.addTab(\"Layout Showdown (improved)\", panel);");
  498. return tabbedPane;
  499. }
  500. public JComponent createAPI_Constraints2()
  501. {
  502. JTabbedPane tabbedPane = new JTabbedPane();
  503. LC layC = new LC().fill().wrap();
  504. AC colC = new AC().align("right", 0).fill(1, 3).grow(100, 1, 3).align("right", 2).gap("15", 1);
  505. AC rowC = new AC().index(6).gap("15!").align("top").grow(100, 8);
  506. JPanel panel = createTabPanel(new MigLayout(layC, colC, rowC)); // Makes the background gradient
  507. // References to text fields not stored to reduce code clutter.
  508. panel.add(new JLabel("Last Name"));
  509. panel.add(new JTextField());
  510. panel.add(new JLabel("First Name"));
  511. panel.add(new JTextField(), new CC().wrap());
  512. panel.add(new JLabel("Phone"));
  513. panel.add(new JTextField());
  514. panel.add(new JLabel("Email"));
  515. panel.add(new JTextField());
  516. panel.add(new JLabel("Address 1"));
  517. panel.add(new JTextField(), new CC().spanX().growX());
  518. panel.add(new JLabel("Address 2"));
  519. panel.add(new JTextField(), new CC().spanX().growX());
  520. panel.add(new JLabel("City"));
  521. panel.add(new JTextField(), new CC().wrap());
  522. panel.add(new JLabel("State"));
  523. panel.add(new JTextField());
  524. panel.add(new JLabel("Postal Code"));
  525. panel.add(new JTextField(10), new CC().spanX(2).growX(0));
  526. panel.add(new JLabel("Country"));
  527. panel.add(new JTextField(), new CC().wrap());
  528. panel.add(createButton("New"), new CC().spanX(5).split(5).tag("other"));
  529. panel.add(createButton("Delete"), new CC().tag("other"));
  530. panel.add(createButton("Edit"), new CC().tag("other"));
  531. panel.add(createButton("Save"), new CC().tag("other"));
  532. panel.add(createButton("Cancel"), new CC().tag("cancel"));
  533. tabbedPane.addTab("Layout Showdown (improved)", panel);
  534. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  535. "\n" +
  536. "LC layC = new LC().fill().wrap();\n" +
  537. "AC colC = new AC().align(\"right\", 0).fill(1, 3).grow(100, 1, 3).align(\"right\", 2).gap(\"15\", 1);\n" +
  538. "AC rowC = new AC().index(6).gap(\"15!\").align(\"top\").grow(100, 8);\n" +
  539. "\n" +
  540. "JPanel panel = createTabPanel(new MigLayout(layC, colC, rowC)); // Makes the background gradient\n" +
  541. "\n" +
  542. "// References to text fields not stored to reduce code clutter.\n" +
  543. "\n" +
  544. "panel.add(new JLabel(\"Last Name\"));\n" +
  545. "panel.add(new JTextField());\n" +
  546. "panel.add(new JLabel(\"First Name\"));\n" +
  547. "panel.add(new JTextField(), new CC().wrap());\n" +
  548. "panel.add(new JLabel(\"Phone\"));\n" +
  549. "panel.add(new JTextField());\n" +
  550. "panel.add(new JLabel(\"Email\"));\n" +
  551. "panel.add(new JTextField());\n" +
  552. "panel.add(new JLabel(\"Address 1\"));\n" +
  553. "panel.add(new JTextField(), new CC().spanX().growX());\n" +
  554. "panel.add(new JLabel(\"Address 2\"));\n" +
  555. "panel.add(new JTextField(), new CC().spanX().growX());\n" +
  556. "panel.add(new JLabel(\"City\"));\n" +
  557. "panel.add(new JTextField(), new CC().wrap());\n" +
  558. "panel.add(new JLabel(\"State\"));\n" +
  559. "panel.add(new JTextField());\n" +
  560. "panel.add(new JLabel(\"Postal Code\"));\n" +
  561. "panel.add(new JTextField(10), new CC().spanX(2).growX(0));\n" +
  562. "panel.add(new JLabel(\"Country\"));\n" +
  563. "panel.add(new JTextField(), new CC().wrap());\n" +
  564. "\n" +
  565. "panel.add(createButton(\"New\"), new CC().spanX(5).split(5).tag(\"other\"));\n" +
  566. "panel.add(createButton(\"Delete\"), new CC().tag(\"other\"));\n" +
  567. "panel.add(createButton(\"Edit\"), new CC().tag(\"other\"));\n" +
  568. "panel.add(createButton(\"Save\"), new CC().tag(\"other\"));\n" +
  569. "panel.add(createButton(\"Cancel\"), new CC().tag(\"cancel\"));\n" +
  570. "\n" +
  571. "tabbedPane.addTab(\"Layout Showdown (improved)\", panel);");
  572. return tabbedPane;
  573. }
  574. public JComponent createLayout_Showdown()
  575. {
  576. JTabbedPane tabbedPane = new JTabbedPane();
  577. JPanel p = createTabPanel(new MigLayout("", "[]15[][grow,fill]15[grow]"));
  578. JScrollPane list1 = new JScrollPane(new JList(new String[] {"Mouse, Mickey"}));
  579. p.add(list1, "spany, growy, wmin 150");
  580. p.add(new JLabel("Last Name"));
  581. p.add(new JTextField());
  582. p.add(new JLabel("First Name"), "split"); // split divides the cell
  583. p.add(new JTextField(), "growx, wrap");
  584. p.add(new JLabel("Phone"));
  585. p.add(new JTextField());
  586. p.add(new JLabel("Email"), "split");
  587. p.add(new JTextField(), "growx, wrap");
  588. p.add(new JLabel("Address 1"));
  589. p.add(new JTextField(), "span, growx"); // span merges cells
  590. p.add(new JLabel("Address 2"));
  591. p.add(new JTextField(), "span, growx");
  592. p.add(new JLabel("City"));
  593. p.add(new JTextField(), "wrap"); // wrap continues on next line
  594. p.add(new JLabel("State"));
  595. p.add(new JTextField());
  596. p.add(new JLabel("Postal Code"), "split");
  597. p.add(new JTextField(), "growx, wrap");
  598. p.add(new JLabel("Country"));
  599. p.add(new JTextField(), "wrap 15");
  600. p.add(createButton("New"), "span, split, align left");
  601. p.add(createButton("Delete"), "");
  602. p.add(createButton("Edit"), "");
  603. p.add(createButton("Save"), "");
  604. p.add(createButton("Cancel"), "wrap push");
  605. tabbedPane.addTab("Layout Showdown (pure)", p);
  606. // Fixed version *******************************************
  607. JPanel p2 = createTabPanel(new MigLayout("", "[]15[][grow,fill]15[][grow,fill]")); // Makes the background gradient
  608. // References to text fields not stored to reduce code clutter.
  609. JScrollPane list2 = new JScrollPane(new JList(new String[] {"Mouse, Mickey"}));
  610. p2.add(list2, "spany, growy, wmin 150");
  611. p2.add(new JLabel("Last Name"));
  612. p2.add(new JTextField());
  613. p2.add(new JLabel("First Name"));
  614. p2.add(new JTextField(), "wrap");
  615. p2.add(new JLabel("Phone"));
  616. p2.add(new JTextField());
  617. p2.add(new JLabel("Email"));
  618. p2.add(new JTextField(), "wrap");
  619. p2.add(new JLabel("Address 1"));
  620. p2.add(new JTextField(), "span");
  621. p2.add(new JLabel("Address 2"));
  622. p2.add(new JTextField(), "span");
  623. p2.add(new JLabel("City"));
  624. p2.add(new JTextField(), "wrap");
  625. p2.add(new JLabel("State"));
  626. p2.add(new JTextField());
  627. p2.add(new JLabel("Postal Code"));
  628. p2.add(new JTextField(10), "growx 0, wrap");
  629. p2.add(new JLabel("Country"));
  630. p2.add(new JTextField(), "wrap 15");
  631. p2.add(createButton("New"), "tag other, span, split");
  632. p2.add(createButton("Delete"), "tag other");
  633. p2.add(createButton("Edit"), "tag other");
  634. p2.add(createButton("Save"), "tag other");
  635. p2.add(createButton("Cancel"), "tag cancel, wrap push");
  636. tabbedPane.addTab("Layout Showdown (improved)", p2);
  637. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  638. "\n" +
  639. "JPanel p = createTabPanel(new MigLayout(\"\", \"[]15[][grow,fill]15[grow]\"));\n" +
  640. "\n" +
  641. "JScrollPane list1 = new JScrollPane(new JList(new String[] {\"Mouse, Mickey\"}));\n" +
  642. "\n" +
  643. "p.add(list1, \"spany, growy, wmin 150\");\n" +
  644. "p.add(new JLabel(\"Last Name\"));\n" +
  645. "p.add(new JTextField());\n" +
  646. "p.add(new JLabel(\"First Name\"), \"split\"); // split divides the cell\n" +
  647. "p.add(new JTextField(), \"growx, wrap\");\n" +
  648. "p.add(new JLabel(\"Phone\"));\n" +
  649. "p.add(new JTextField());\n" +
  650. "p.add(new JLabel(\"Email\"), \"split\");\n" +
  651. "p.add(new JTextField(), \"growx, wrap\");\n" +
  652. "p.add(new JLabel(\"Address 1\"));\n" +
  653. "p.add(new JTextField(), \"span, growx\"); // span merges cells\n" +
  654. "p.add(new JLabel(\"Address 2\"));\n" +
  655. "p.add(new JTextField(), \"span, growx\");\n" +
  656. "p.add(new JLabel(\"City\"));\n" +
  657. "p.add(new JTextField(), \"wrap\"); // wrap continues on next line\n" +
  658. "p.add(new JLabel(\"State\"));\n" +
  659. "p.add(new JTextField());\n" +
  660. "p.add(new JLabel(\"Postal Code\"), \"split\");\n" +
  661. "p.add(new JTextField(), \"growx, wrap\");\n" +
  662. "p.add(new JLabel(\"Country\"));\n" +
  663. "p.add(new JTextField(), \"wrap 15\");\n" +
  664. "\n" +
  665. "p.add(createButton(\"New\"), \"span, split, align left\");\n" +
  666. "p.add(createButton(\"Delete\"), \"\");\n" +
  667. "p.add(createButton(\"Edit\"), \"\");\n" +
  668. "p.add(createButton(\"Save\"), \"\");\n" +
  669. "p.add(createButton(\"Cancel\"), \"wrap push\");\n" +
  670. "\n" +
  671. "tabbedPane.addTab(\"Layout Showdown (pure)\", p);" +
  672. "\n" +
  673. "\t\t// Fixed version *******************************************\n" +
  674. "JPanel p2 = createTabPanel(new MigLayout(\"\", \"[]15[][grow,fill]15[][grow,fill]\")); // Makes the background gradient\n" +
  675. "\n" +
  676. "// References to text fields not stored to reduce code clutter.\n" +
  677. "\n" +
  678. "JScrollPane list2 = new JScrollPane(new JList(new String[] {\"Mouse, Mickey\"}));\n" +
  679. "p2.add(list2, \"spany, growy, wmin 150\");\n" +
  680. "p2.add(new JLabel(\"Last Name\"));\n" +
  681. "p2.add(new JTextField());\n" +
  682. "p2.add(new JLabel(\"First Name\"));\n" +
  683. "p2.add(new JTextField(), \"wrap\");\n" +
  684. "p2.add(new JLabel(\"Phone\"));\n" +
  685. "p2.add(new JTextField());\n" +
  686. "p2.add(new JLabel(\"Email\"));\n" +
  687. "p2.add(new JTextField(), \"wrap\");\n" +
  688. "p2.add(new JLabel(\"Address 1\"));\n" +
  689. "p2.add(new JTextField(), \"span\");\n" +
  690. "p2.add(new JLabel(\"Address 2\"));\n" +
  691. "p2.add(new JTextField(), \"span\");\n" +
  692. "p2.add(new JLabel(\"City\"));\n" +
  693. "p2.add(new JTextField(), \"wrap\");\n" +
  694. "p2.add(new JLabel(\"State\"));\n" +
  695. "p2.add(new JTextField());\n" +
  696. "p2.add(new JLabel(\"Postal Code\"));\n" +
  697. "p2.add(new JTextField(10), \"growx 0, wrap\");\n" +
  698. "p2.add(new JLabel(\"Country\"));\n" +
  699. "p2.add(new JTextField(), \"wrap 15\");\n" +
  700. "\n" +
  701. "p2.add(createButton(\"New\"), \"tag other, span, split\");\n" +
  702. "p2.add(createButton(\"Delete\"), \"tag other\");\n" +
  703. "p2.add(createButton(\"Edit\"), \"tag other\");\n" +
  704. "p2.add(createButton(\"Save\"), \"tag other\");\n" +
  705. "p2.add(createButton(\"Cancel\"), \"tag cancel, wrap push\");\n" +
  706. "\n" +
  707. "tabbedPane.addTab(\"Layout Showdown (improved)\", p2);");
  708. return tabbedPane;
  709. }
  710. public JComponent createWelcome()
  711. {
  712. JTabbedPane tabbedPane = new JTabbedPane();
  713. MigLayout lm = new MigLayout("ins 20, fill", "", "[grow]unrel[]");
  714. JPanel mainPanel = createTabPanel(lm);
  715. String s = "MigLayout's main purpose is to make layouts for SWT and Swing, and possibly other frameworks, much more powerful and a lot easier to create, especially for manual coding.\n\n" +
  716. "The motto is: \"MigLayout makes complex layouts easy and normal layouts one-liners.\"\n\n" +
  717. "The layout engine is very flexible and advanced, something that is needed to make it simple to use yet handle almost all layout use-cases.\n\n" +
  718. "MigLayout can handle all layouts that the commonly used Swing Layout Managers can handle and this with a lot of extra features. " +
  719. "It also incorporates most, if not all, of the open source alternatives FormLayout's and TableLayout's functionality." +
  720. "\n\n\nThanks to Karsten Lentzsch of JGoodies.com for allowing the reuse of the main demo application layout and for his inspiring talks that led to this layout Manager." +
  721. "\n\n\nMikael Grev\n" +
  722. "MiG InfoCom AB\n" +
  723. "miglayout@miginfocom.com";
  724. JTextArea textArea = new JTextArea(s);
  725. textArea.setEditable(false);
  726. textArea.setSize(400, 400);
  727. if (PlatformDefaults.getCurrentPlatform() == PlatformDefaults.WINDOWS_XP)
  728. textArea.setFont(new Font("tahoma", Font.BOLD, 11));
  729. textArea.setOpaque(OPAQUE);
  730. textArea.setWrapStyleWord(true);
  731. textArea.setLineWrap(true);
  732. JLabel label = new JLabel("You can Right Click any Component or Container to change the constraints for it!");
  733. label.setForeground(new Color(200, 0, 0));
  734. mainPanel.add(textArea, "w 500:pref,ay top,grow,wrap");
  735. mainPanel.add(label, "growx");
  736. label.setFont(label.getFont().deriveFont(Font.BOLD));
  737. tabbedPane.addTab("Welcome", mainPanel);
  738. setSource("");
  739. return tabbedPane;
  740. }
  741. public JComponent createVisual_Bounds()
  742. {
  743. JTabbedPane tabbedPane = new JTabbedPane();
  744. // "NON"-corrected bounds
  745. JPanel p1 = createTabPanel(new MigLayout("fill, ins 3, novisualpadding"));
  746. p1.setBorder(new LineBorder(Color.BLACK));
  747. JTabbedPane demoPane2 = new JTabbedPane();
  748. JPanel demoPanel2 = new JPanel();
  749. demoPanel2.setBackground(Color.WHITE);
  750. demoPane2.addTab("Demo Tab", demoPanel2);
  751. p1.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
  752. p1.add(demoPane2, "grow, aligny bottom");
  753. p1.add(createTextField("A JTextField", 100), "grow, aligny bottom, wmin 100");
  754. p1.add(createTextArea("A JTextArea", 1, 100), "newline,grow, aligny bottom, wmin 100");
  755. p1.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
  756. p1.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
  757. JPanel p2 = createTabPanel(new MigLayout("center,center,fill,ins 3"));
  758. p2.setBorder(new LineBorder(Color.BLACK));
  759. JTabbedPane demoPane = new JTabbedPane();
  760. JPanel demoPanel = new JPanel();
  761. demoPanel.setBackground(Color.WHITE);
  762. demoPane.addTab("Demo Tab", demoPanel);
  763. p2.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
  764. p2.add(demoPane, "grow, aligny bottom");
  765. p2.add(createTextField("A JTextField", 100), "grow, aligny bottom, wmin 100");
  766. p2.add(createTextArea("A JTextArea", 1, 100), "newline,grow, aligny bottom, wmin 100");
  767. p2.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
  768. p2.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
  769. tabbedPane.addTab("Visual Bounds (Not Corrected)", p1);
  770. tabbedPane.addTab("Visual Bounds (Corrected on XP)", p2);
  771. // Disregard. Just forgetting the source code text close to the source code.
  772. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  773. "\n" +
  774. "// \"NON\"-corrected bounds\n" +
  775. "JPanel p1 = createTabPanel(new MigLayout(\"fill, ins 3, novisualpadding\"));\n" +
  776. "p1.setBorder(new LineBorder(Color.BLACK));\n" +
  777. "\n" +
  778. "JTabbedPane demoPane2 = new JTabbedPane();\n" +
  779. "JPanel demoPanel2 = new JPanel();\n" +
  780. "demoPanel2.setBackground(Color.WHITE);\n" +
  781. "demoPane2.addTab(\"Demo Tab\", demoPanel2);\n" +
  782. "\n" +
  783. "p1.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
  784. "p1.add(demoPane2, \"grow, aligny bottom\");\n" +
  785. "p1.add(createTextField(\"A JTextField\", 100), \"grow, aligny bottom, wmin 100\");\n" +
  786. "p1.add(createTextArea(\"A JTextArea\", 1, 100), \"newline,grow, aligny bottom, wmin 100\");\n" +
  787. "p1.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
  788. "p1.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
  789. "\n" +
  790. "JPanel p2 = createTabPanel(new MigLayout(\"center,center,fill,ins 3\"));\n" +
  791. "p2.setBorder(new LineBorder(Color.BLACK));\n" +
  792. "\n" +
  793. "JTabbedPane demoPane = new JTabbedPane();\n" +
  794. "JPanel demoPanel = new JPanel();\n" +
  795. "demoPanel.setBackground(Color.WHITE);\n" +
  796. "demoPane.addTab(\"Demo Tab\", demoPanel);\n" +
  797. "\n" +
  798. "p2.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
  799. "p2.add(demoPane, \"grow, aligny bottom\");\n" +
  800. "p2.add(createTextField(\"A JTextField\", 100), \"grow, aligny bottom, wmin 100\");\n" +
  801. "p2.add(createTextArea(\"A JTextArea\", 1, 100), \"newline,grow, aligny bottom, wmin 100\");\n" +
  802. "p2.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
  803. "p2.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
  804. "\n" +
  805. "tabbedPane.addTab(\"Visual Bounds (Not Corrected)\", p1);\n" +
  806. "tabbedPane.addTab(\"Visual Bounds (Corrected on XP)\", p2);");
  807. return tabbedPane;
  808. }
  809. public JComponent createDocking()
  810. {
  811. JTabbedPane tabbedPane = new JTabbedPane();
  812. JPanel p1 = createTabPanel(new MigLayout("fill"));
  813. p1.add(createPanel("1. North"), "north");
  814. p1.add(createPanel("2. West"), "west");
  815. p1.add(createPanel("3. East"), "east");
  816. p1.add(createPanel("4. South"), "south");
  817. String[][] data = new String[20][6];
  818. for (int r = 0; r < data.length; r++) {
  819. data[r] = new String[6];
  820. for (int c = 0; c < data[r].length; c++)
  821. data[r][c] = "Cell " + (r + 1) + ", " + (c + 1);
  822. }
  823. JTable table = new JTable(data, new String[] {"Column 1", "Column 2", "Column 3", "Column 4", "Column 5", "Column 6"});
  824. p1.add(new JScrollPane(table), "grow");
  825. JPanel p2 = createTabPanel(new MigLayout("fill", "[c]", ""));
  826. p2.add(createPanel("1. North"), "north");
  827. p2.add(createPanel("2. North"), "north");
  828. p2.add(createPanel("3. West"), "west");
  829. p2.add(createPanel("4. West"), "west");
  830. p2.add(createPanel("5. South"), "south");
  831. p2.add(createPanel("6. East"), "east");
  832. p2.add(createButton("7. Normal"));
  833. p2.add(createButton("8. Normal"));
  834. p2.add(createButton("9. Normal"));
  835. JPanel p3 = createTabPanel(new MigLayout());
  836. p3.add(createPanel("1. North"), "north");
  837. p3.add(createPanel("2. South"), "south");
  838. p3.add(createPanel("3. West"), "west");
  839. p3.add(createPanel("4. East"), "east");
  840. p3.add(createButton("5. Normal"));
  841. JPanel p4 = createTabPanel(new MigLayout());
  842. p4.add(createPanel("1. North"), "north");
  843. p4.add(createPanel("2. North"), "north");
  844. p4.add(createPanel("3. West"), "west");
  845. p4.add(createPanel("4. West"), "west");
  846. p4.add(createPanel("5. South"), "south");
  847. p4.add(createPanel("6. East"), "east");
  848. p4.add(createButton("7. Normal"));
  849. p4.add(createButton("8. Normal"));
  850. p4.add(createButton("9. Normal"));
  851. JPanel p5 = createTabPanel(new MigLayout("fillx", "[c]", ""));
  852. p5.add(createPanel("1. North"), "north");
  853. p5.add(createPanel("2. North"), "north");
  854. p5.add(createPanel("3. West"), "west");
  855. p5.add(createPanel("4. West"), "west");
  856. p5.add(createPanel("5. South"), "south");
  857. p5.add(createPanel("6. East"), "east");
  858. p5.add(createButton("7. Normal"));
  859. p5.add(createButton("8. Normal"));
  860. p5.add(createButton("9. Normal"));
  861. JPanel p6 = createTabPanel(new MigLayout("fill", "", ""));
  862. Random rand = new Random();
  863. String[] sides = {"north", "east", "south", "west"};
  864. for (int i = 0; i < 20; i++) {
  865. int side = rand.nextInt(4);
  866. p6.add(createPanel((i + 1) + " " + sides[side]), sides[side]);
  867. }
  868. p6.add(createPanel("I'm in the Center!"), "dock center");
  869. tabbedPane.addTab("Docking 1 (fill)", p1);
  870. tabbedPane.addTab("Docking 2 (fill)", p2);
  871. tabbedPane.addTab("Docking 3", p3);
  872. tabbedPane.addTab("Docking 4", p4);
  873. tabbedPane.addTab("Docking 5 (fillx)", p5);
  874. tabbedPane.addTab("Random Docking", new JScrollPane(p6));
  875. // Disregard. Just forgetting the source code text close to the source code.
  876. setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
  877. "\n" +
  878. "JPanel p1 = createTabPanel(new MigLayout(\"fill\"));\n" +
  879. "\n" +
  880. "p1.add(createPanel(\"1. North\"), \"north\");\n" +
  881. "p1.add(createPanel(\"2. West\"), \"west\");\n" +
  882. "p1.add(createPanel(\"3. East\"), \"east\");\n" +
  883. "p1.add(createPanel(\"4. South\"), \"south\");\n" +
  884. "\n" +
  885. "String[][] data = new String[20][6];\n" +
  886. "for (int r = 0; r < data.length; r++) {\n" +
  887. "\tdata[r] = new String[6];\n" +
  888. "\tfor (int c = 0; c < data[r].length; c++)\n" +
  889. "\t\tdata[r][c] = \"Cell \" + (r + 1) + \", \" + (c + 1);\n" +
  890. "}\n" +
  891. "JTable table = new …

Large files files are truncated, but you can click here to view the full file