/** * This method will read the standard input and save the content to a temporary. source file since * the source file will be parsed mutiple times. The HTML source file is parsed and checked for * Charset in HTML tags at first time, then source file is parsed again for the converting The * temporary file is read from standard input and saved in current directory and will be deleted * after the conversion has completed. * * @return the vector of the converted temporary source file name */ public Vector getStandardInput() throws FileAccessException { byte[] buf = new byte[2048]; int len = 0; FileInputStream fis = null; FileOutputStream fos = null; File tempSourceFile; String tmpSourceName = ".tmpSource_stdin"; File outFile = new File(tmpSourceName); tempSourceFile = new File(System.getProperty("user.dir") + sep + tmpSourceName); if (!tempSourceFile.exists()) { try { fis = new FileInputStream(FileDescriptor.in); fos = new FileOutputStream(outFile); while ((len = fis.read(buf, 0, 2048)) != -1) fos.write(buf, 0, len); } catch (IOException e) { System.out.println(ResourceHandler.getMessage("plugin_converter.write_permission")); return null; } } else { throw new FileAccessException(ResourceHandler.getMessage("plugin_converter.overwrite")); } tempSourceFile = new File(System.getProperty("user.dir") + sep + tmpSourceName); if (tempSourceFile.exists()) { fileSpecs.add(tmpSourceName); return fileSpecs; } else { throw new FileAccessException( ResourceHandler.getMessage("plugin_converter.write_permission")); } }
/** * This method will take in a string which will be a directory. It will make sure that the * directory exists and return the absolute path * * @return the value of the absolute directory */ private String doesExistAndAbsolute(String dir) { File tempDirFile = new File(dir); try { if (tempDirFile.exists()) { if (tempDirFile.isAbsolute()) { return dir; } else { tempDirFile = new File(System.getProperty("user.dir") + sep + dir); if (tempDirFile.exists()) { return tempDirFile.getAbsolutePath(); } else { throw new NotDirectoryException( ResourceHandler.getMessage("caption.reldirnotfound") + ": " + tempDirFile.getAbsolutePath()); } } } else { throw new NotDirectoryException( ResourceHandler.getMessage("caption.absdirnotfound") + ": " + tempDirFile.getAbsolutePath()); } } catch (NotDirectoryException e) { System.out.println( ResourceHandler.getMessage("caption.absdirnotfound") + ": " + tempDirFile.getAbsolutePath()); return null; // this is just so it would compile } }
private void showAboutDialog() { final String aboutCaption = ResourceHandler.getMessage("about_dialog.caption"); // Version string final String version = System.getProperty("java.version"); MessageFormat formatter = new MessageFormat(ResourceHandler.getMessage("about_dialog.info")); final String aboutInfo = formatter.format(new Object[] {version}); JOptionPane.showMessageDialog(this, aboutInfo, aboutCaption, JOptionPane.INFORMATION_MESSAGE); }
/** Displayed when the template file is not found in the classpath or the working directory. */ private void showNoTemplateDialog() { final String caption = ResourceHandler.getMessage("notemplate_dialog.caption"); MessageFormat formatter = new MessageFormat(ResourceHandler.getMessage("notemplate_dialog.info")); final String info = formatter.format(new Object[] {PluginConverter.getDefaultTemplateFileName()}); JOptionPane.showMessageDialog(this, info, caption, JOptionPane.ERROR_MESSAGE); System.exit(0); }
/** Returns false if Exception is thrown. */ private boolean setDirectory() { String pathStr = dirTF.getText().trim(); if (pathStr.equals("")) pathStr = System.getProperty("user.dir"); try { File dirPath = new File(pathStr); if (!dirPath.isDirectory()) { if (!dirPath.exists()) { if (recursiveCheckBox.isSelected()) throw new NotDirectoryException(dirPath.getAbsolutePath()); else throw new NotFileException(dirPath.getAbsolutePath()); } else { convertSet.setFile(dirPath); convertSet.setDestinationPath(dirPath.getParentFile()); } } else { // Set the descriptors setMatchingFileNames(); FlexFilter flexFilter = new FlexFilter(); flexFilter.addDescriptors(descriptors); flexFilter.setFilesOnly(!recursiveCheckBox.isSelected()); convertSet.setSourcePath(dirPath, flexFilter); convertSet.setDestinationPath(dirPath); } } catch (NotDirectoryException e1) { final String caption = ResourceHandler.getMessage("notdirectory_dialog.caption1"); MessageFormat formatter; String info_msg; if (pathStr.equals("")) { info_msg = ResourceHandler.getMessage("notdirectory_dialog.info5"); } else { formatter = new MessageFormat(ResourceHandler.getMessage("notdirectory_dialog.info0")); info_msg = formatter.format(new Object[] {pathStr}); } final String info = info_msg; JOptionPane.showMessageDialog(this, info, caption, JOptionPane.ERROR_MESSAGE); return false; } catch (NotFileException e2) { final String caption = ResourceHandler.getMessage("notdirectory_dialog.caption0"); MessageFormat formatter = new MessageFormat(ResourceHandler.getMessage("notdirectory_dialog.info1")); final String info = formatter.format(new Object[] {pathStr}); JOptionPane.showMessageDialog(this, info, caption, JOptionPane.ERROR_MESSAGE); return false; } return true; // no exception thrown }
/** * Pop-up a Dialog if the source and backup fields are the same. Returns true if the source and * backup remain the same. */ private boolean testSourceVsBackup() { if (dirTF.getText().equals(backupTF.getText())) { final String caption = ResourceHandler.getMessage("caption.warning"); MessageFormat formatter = new MessageFormat(ResourceHandler.getMessage("warning_dialog.info")); final String info = formatter.format(new Object[] {backupTF.getText()}); int n = JOptionPane.showConfirmDialog(this, info, caption, JOptionPane.WARNING_MESSAGE); if (n == JOptionPane.YES_OPTION) { backupTF.setText(backupTF.getText() + "_BAK"); return false; } else if (n == JOptionPane.NO_OPTION) return true; } return false; }
/** Set the template file path. */ private boolean setTemplateFile(String pathStr) { File templateFile = new File(templateCh.getSelectedPath(pathStr)); if (!templateFile.getName().toLowerCase().endsWith(".tpl")) { final String templateCaption = ResourceHandler.getMessage("nottemplatefile_dialog.caption"); MessageFormat formatter = new MessageFormat(ResourceHandler.getMessage("nottemplatefile_dialog.info0")); final String errorMessage = formatter.format(new Object[] {templateFile.getName()}); String defaultTemplateName = PluginConverter.getDefaultTemplateFileName(); JOptionPane.showMessageDialog(this, errorMessage, templateCaption, JOptionPane.ERROR_MESSAGE); templateCh.select(templateCh.getPreviousSelection()); return false; } try { converter.setTemplateFilePath(templateCh.getSelectedPath(pathStr)); } catch (FileNotFoundException e) { // TO-DO: found it, but it's not a file. // TO-DO: Throw up a Dialog -- "Not a valid file, resetting to default file" final String caption = ResourceHandler.getMessage("notdirectory_dialog.caption0"); MessageFormat formatter; String info_msg; if (pathStr.equals("")) { info_msg = ResourceHandler.getMessage("notdirectory_dialog.info5"); } else { formatter = new MessageFormat(ResourceHandler.getMessage("notdirectory_dialog.info1")); info_msg = formatter.format(new Object[] {pathStr}); } final String info = info_msg; JOptionPane.showMessageDialog(this, info, caption, JOptionPane.ERROR_MESSAGE); return false; } return true; }
/** * This will make sure the destination path isn't the same as the backup directory, the * application will terminate if they are the same */ private void checkForProblems() throws CommandLineException { if ((backupStr != null) && (destStr != null)) { File fBackupTemp = new File(backupStr); File fDestTemp = new File(destStr); if ((fDestTemp.getAbsolutePath()).equals(fBackupTemp.getAbsolutePath())) { System.out.println(ResourceHandler.getMessage("illegal_source_and_backup.info")); throw new CommandLineException(); } } }
/** Creates new ConverterGUI Frame. */ public ConverterGUI() { super(ResourceHandler.getMessage("product_name")); // UniCode (tm) == \u2122 try { converter = new PluginConverter(); converter.setShowProgressStdOut(false); } catch (FileNotFoundException e) { showNoTemplateDialog(); } converter.setConvertSet(convertSet = new DefaultSet()); setResizable(true); majorLayout(); setup(); }
/** Handle ItemEvents. */ public void itemStateChanged(ItemEvent e) { final String dialog_title = ResourceHandler.getMessage("template_dialog.title"); Component target = (Component) e.getSource(); if (target == recursiveCheckBox) { converter.setRecurse(recursiveCheckBox.isSelected()); } else if (target == staticVersioningRadioButton || target == dynamicVersioningRadioButton) { converter.setStaticVersioning(staticVersioningRadioButton.isSelected()); } else if (target == templateCh && (e.getStateChange() == e.SELECTED)) { // Process only when item is Selected // Get the current template selection String choiceStr = (String) templateCh.getSelectedItem(); // If the user chooses 'other', display a file dialog to allow // them to select a template file. if (choiceStr.equals(TemplateFileChoice.OTHER_STR)) { String templatePath = null; FileDialog fd = new FileDialog(this, dialog_title, FileDialog.LOAD); fd.show(); // Capture the path entered, if any. if (fd.getDirectory() != null && fd.getFile() != null) { templatePath = fd.getDirectory() + fd.getFile(); } // If the template file is valid add it and select it. if (templatePath != null && setTemplateFile(templatePath)) { if (!templateCh.testIfInList(templatePath)) { templateCh.addItem(templatePath); } templateCh.select(templatePath); } else { templateCh.select(templateCh.getPreviousSelection()); } fd.dispose(); } else { templateCh.select(choiceStr); } } }
/** * This will take in the string given at the command line by the user find if it is null and calls * readline(). * * @param s[] holds the given command line string */ public CommandLine(String s[]) throws CommandLineException, IndexOutOfBoundsException { if (s == null || s.length == 0) { // there are no params params = false; } else { params = true; commandLine = s; readLine(); // // If no files are specified, default. // if ((isStdIn() == false) && fileSpecs.isEmpty()) { String specs = ResourceHandler.getMessage("converter_gui.lablel2"); StringTokenizer st = new StringTokenizer(specs, " ,"); while (st.hasMoreTokens()) { fileSpecs.add(st.nextToken()); } } checkForProblems(); } }
// ---------------------------------------------------------------------------------------- // class TemplateFileChoice extends JComboBox { public static final int DEFAULT = 0, EXTEND = 1, IE = 2, NS = 3, SEPARATOR = 4, OTHER = 5; public static final String DEFAULT_STR = ResourceHandler.getMessage("template.default"), EXTEND_STR = ResourceHandler.getMessage("template.extend"), IE_STR = ResourceHandler.getMessage("template.ieonly"), NS_STR = ResourceHandler.getMessage("template.nsonly"), SEPARATOR_STR = "-----------------------------------------------------------------------", OTHER_STR = ResourceHandler.getMessage("template.other"); public static final String DEFAULT_PATH = "templates/default.tpl", EXTEND_PATH = "templates/extend.tpl", IE_PATH = "templates/ieonly.tpl", NS_PATH = "templates/nsonly.tpl"; private String previousSelection = DEFAULT_STR; private PluginConverter converter = ConverterGUI.getPluginConverter(); public TemplateFileChoice() { super(); // Define and set our JComboBox model String[] modelStrings = {DEFAULT_STR, EXTEND_STR, IE_STR, NS_STR, SEPARATOR_STR, OTHER_STR}; setModel(new DefaultComboBoxModel(modelStrings)); } public void select(String item) { if (item.equals(SEPARATOR_STR)) item = previousSelection; else previousSelection = item; setSelectedItem(item); } public String getPreviousSelection() { return previousSelection; } public String getSelectedPath(String item) { String path = "", fileSep = System.getProperty("file.separator"); /* try { path = converter.getDefaultTemplateFilePath().getParent() + fileSep; } catch (FileNotFoundException e) { final String caption = ResourceHandler.getMessage("notemplate_dialog.caption"); final String info = ResourceHandler.getMessage("notemplate_dialog.info0") + PluginConverter.getDefaultTemplateFileName() + ResourceHandler.getMessage("notemplate_dialog.info1"); JOptionPane.showMessageDialog(this, info, caption, JOptionPane.ERROR_MESSAGE); System.exit(0); } */ if (item.equals(DEFAULT_STR)) return path + DEFAULT_PATH; else if (item.equals(EXTEND_STR)) return path + EXTEND_PATH; else if (item.equals(IE_STR)) return path + IE_PATH; else if (item.equals(NS_STR)) return path + NS_PATH; else return item; } public boolean testIfInList(String item) { for (int i = 0; i < getItemCount(); i++) { if (getItemAt(i).equals(item)) return true; } return false; } }
/** Creates the GUI. */ public void majorLayout() { // // Setup Menu // JMenuBar menuBar = new JMenuBar(); JMenu file = new JMenu(ResourceHandler.getMessage("menu.file")); file.setMnemonic(ResourceHandler.getAcceleratorKey("menu.file")); file.add(exitMenuItem = new JMenuItem(ResourceHandler.getMessage("menu.exit"))); exitMenuItem.setMnemonic(ResourceHandler.getAcceleratorKey("menu.exit")); exitMenuItem.addActionListener(this); menuBar.add(file); JMenu edit = new JMenu(ResourceHandler.getMessage("menu.edit")); edit.setMnemonic(ResourceHandler.getAcceleratorKey("menu.edit")); edit.add(optionMenuItem = new JMenuItem(ResourceHandler.getMessage("menu.option"))); optionMenuItem.setMnemonic(ResourceHandler.getAcceleratorKey("menu.option")); optionMenuItem.addActionListener(this); menuBar.add(edit); JMenu help = new JMenu(ResourceHandler.getMessage("menu.help")); help.setMnemonic(ResourceHandler.getAcceleratorKey("menu.help")); help.add(helpMenuItem = new JMenuItem(ResourceHandler.getMessage("menu.help"))); helpMenuItem.setMnemonic(ResourceHandler.getAcceleratorKey("menu.help")); help.add(new JSeparator()); help.add(aboutMenuItem = new JMenuItem(ResourceHandler.getMessage("menu.about"))); aboutMenuItem.setMnemonic(ResourceHandler.getAcceleratorKey("menu.about")); helpMenuItem.addActionListener(this); aboutMenuItem.addActionListener(this); menuBar.add(help); setJMenuBar(menuBar); // // Setup main GUI // dirLabel = new JLabel(ResourceHandler.getMessage("converter_gui.lablel0")); dirTF = new JTextField(); dirBttn = new JButton(ResourceHandler.getMessage("button.browse.dir")); dirBttn.setMnemonic(ResourceHandler.getAcceleratorKey("button.browse.dir")); matchingLabel = new JLabel(ResourceHandler.getMessage("converter_gui.lablel1")); matchingTF = new JTextField(ResourceHandler.getMessage("converter_gui.lablel2")); recursiveCheckBox = new JCheckBox(ResourceHandler.getMessage("converter_gui.lablel3")); recursiveCheckBox.setMnemonic(ResourceHandler.getAcceleratorKey("converter_gui.lablel3")); backupLabel = new JLabel(ResourceHandler.getMessage("converter_gui.lablel5")); backupTF = new JTextField(); backupBttn = new JButton(ResourceHandler.getMessage("button.browse.backup")); backupBttn.setMnemonic(ResourceHandler.getAcceleratorKey("button.browse.backup")); templateLabel = new JLabel(ResourceHandler.getMessage("converter_gui.lablel7")); templateCh = new TemplateFileChoice(); staticVersioningLabel = new JLabel(ResourceHandler.getMessage("static.versioning.label")); String version = System.getProperty("java.version"); if (version.indexOf("-") > 0) { version = version.substring(0, version.indexOf("-")); } int dotIndex = version.indexOf("."); dotIndex = version.indexOf(".", dotIndex + 1); String familyVersion = version.substring(0, dotIndex); MessageFormat formatter = new MessageFormat(ResourceHandler.getMessage("static.versioning.radio.button")); staticVersioningRadioButton = new JRadioButton(formatter.format(new Object[] {version})); staticVersioningRadioButton.setMnemonic( ResourceHandler.getAcceleratorKey("static.versioning.radio.button")); formatter = new MessageFormat(ResourceHandler.getMessage("dynamic.versioning.radio.button")); dynamicVersioningRadioButton = new JRadioButton(formatter.format(new Object[] {familyVersion})); dynamicVersioningRadioButton.setMnemonic( ResourceHandler.getAcceleratorKey("dynamic.versioning.radio.button")); staticVersioningTextArea = new JTextArea(ResourceHandler.getMessage("static.versioning.text")); formatter = new MessageFormat(ResourceHandler.getMessage("dynamic.versioning.text")); dynamicVersioningTextArea = new JTextArea(formatter.format(new Object[] {familyVersion})); ButtonGroup versioningButtonGroup = new ButtonGroup(); versioningButtonGroup.add(staticVersioningRadioButton); versioningButtonGroup.add(dynamicVersioningRadioButton); runBttn = new JButton(ResourceHandler.getMessage("button.convert")); runBttn.setMnemonic(ResourceHandler.getAcceleratorKey("button.convert")); recursiveCheckBox.setOpaque(false); staticVersioningRadioButton.setOpaque(false); dynamicVersioningRadioButton.setOpaque(false); staticVersioningTextArea.setEditable(false); staticVersioningTextArea.setLineWrap(true); staticVersioningTextArea.setWrapStyleWord(true); dynamicVersioningTextArea.setEditable(false); dynamicVersioningTextArea.setLineWrap(true); dynamicVersioningTextArea.setWrapStyleWord(true); staticVersioningPanel.setLayout(new BorderLayout()); staticVersioningPanel.add(staticVersioningTextArea, "Center"); staticVersioningPanel.setBorder(new LineBorder(Color.black)); dynamicVersioningPanel.setLayout(new BorderLayout()); dynamicVersioningPanel.add(dynamicVersioningTextArea, "Center"); dynamicVersioningPanel.setBorder(new LineBorder(Color.black)); if (converter.isStaticVersioning()) { staticVersioningRadioButton.setSelected(true); } else { dynamicVersioningRadioButton.setSelected(true); } addListeners(); final int buf = 10, // Buffer (between components and form) sp = 10, // Space between components vsp = 5, // Vertical space indent = 20; // Indent between form (left edge) and component GridBagConstraints gbc = new GridBagConstraints(); GridBagLayout gbl = new GridBagLayout(); getContentPane().setLayout(gbl); // // Setup top panel // GridBagLayout topLayout = new GridBagLayout(); JPanel topPanel = new JPanel(); topPanel.setOpaque(false); topPanel.setLayout(topLayout); topLayout.setConstraints( dirLabel, new GridBagConstraints( 0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), 0, 0)); topLayout.setConstraints( dirTF, new GridBagConstraints( 1, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(vsp, 2, 0, 0), 0, 0)); topLayout.setConstraints( dirBttn, new GridBagConstraints( 2, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, sp, 0, 0), 0, 0)); topLayout.setConstraints( matchingLabel, new GridBagConstraints( 0, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), 0, 0)); topLayout.setConstraints( matchingTF, new GridBagConstraints( 1, 1, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(vsp, 2, 0, 0), 0, 0)); topLayout.setConstraints( recursiveCheckBox, new GridBagConstraints( 2, 1, GridBagConstraints.REMAINDER, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(vsp, 10, 0, 0), 0, 0)); topLayout.setConstraints( backupLabel, new GridBagConstraints( 0, 3, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), 0, 0)); topLayout.setConstraints( backupTF, new GridBagConstraints( 1, 3, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(vsp, 2, 0, 0), 0, 0)); topLayout.setConstraints( backupBttn, new GridBagConstraints( 2, 3, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, sp, 0, 0), 0, 0)); topLayout.setConstraints( templateLabel, new GridBagConstraints( 0, 4, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), 0, 0)); topLayout.setConstraints( templateCh, new GridBagConstraints( 1, 4, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(vsp, 2, 0, 0), 0, 0)); topLayout.setConstraints( sep1, new GridBagConstraints( 0, 5, GridBagConstraints.REMAINDER, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 10, 10), 0, 0)); topLayout.setConstraints( staticVersioningLabel, new GridBagConstraints( 0, 6, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), 0, 0)); topLayout.setConstraints( staticVersioningRadioButton, new GridBagConstraints( 0, 7, GridBagConstraints.REMAINDER, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(vsp, 10, 0, 0), 0, 0)); topLayout.setConstraints( staticVersioningPanel, new GridBagConstraints( 0, 8, GridBagConstraints.REMAINDER, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(vsp, 25, 10, 0), 0, 0)); topLayout.setConstraints( dynamicVersioningRadioButton, new GridBagConstraints( 0, 9, GridBagConstraints.REMAINDER, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(vsp, 10, 0, 0), 0, 0)); topLayout.setConstraints( dynamicVersioningPanel, new GridBagConstraints( 0, 10, GridBagConstraints.REMAINDER, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(vsp, 25, 0, 0), 0, 0)); topLayout.setConstraints( sep2, new GridBagConstraints( 0, 11, GridBagConstraints.REMAINDER, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 0, 10), 0, 0)); invisibleBttn = new JButton(); invisibleBttn.setVisible(false); topLayout.setConstraints( invisibleBttn, new GridBagConstraints( 2, 6, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.CENTER, new Insets(indent, sp, 0, 0), 0, 0)); topPanel.add(dirLabel); topPanel.add(dirTF); topPanel.add(dirBttn); topPanel.add(matchingLabel); topPanel.add(matchingTF); topPanel.add(recursiveCheckBox); topPanel.add(backupLabel); topPanel.add(backupTF); topPanel.add(backupBttn); topPanel.add(templateLabel); topPanel.add(templateCh); topPanel.add(sep1); topPanel.add(staticVersioningLabel); topPanel.add(staticVersioningRadioButton); topPanel.add(staticVersioningPanel); topPanel.add(dynamicVersioningRadioButton); topPanel.add(dynamicVersioningPanel); topPanel.add(sep2); topPanel.add(invisibleBttn); // // Setup bottom panel // GridBagLayout buttomLayout = new GridBagLayout(); JPanel buttomPanel = new JPanel(); buttomPanel.setOpaque(false); buttomPanel.setLayout(buttomLayout); buttomLayout.setConstraints( runBttn, new GridBagConstraints( 3, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(sp, 0, 0, 0), 0, 0)); buttomPanel.add(runBttn); // // Setup main panel // GridBagLayout mainLayout = new GridBagLayout(); JPanel mainPanel = new JPanel(); mainPanel.setOpaque(false); mainPanel.setLayout(mainLayout); mainLayout.setConstraints( topPanel, new GridBagConstraints( 0, 0, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(buf, buf, 0, buf), 0, 0)); mainLayout.setConstraints( buttomPanel, new GridBagConstraints( 0, 1, 1, 1, 1, 1, GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, buf, buf, buf), 0, 0)); mainPanel.add(topPanel); mainPanel.add(buttomPanel); Border border = BorderFactory.createEtchedBorder(); mainPanel.setBorder(border); GridBagLayout layout = new GridBagLayout(); getContentPane().setLayout(layout); layout.setConstraints( mainPanel, new GridBagConstraints( 0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); getContentPane().add(mainPanel); pack(); setResizable(false); }