List of usage examples for java.awt GridBagConstraints HORIZONTAL
int HORIZONTAL
To view the source code for java.awt GridBagConstraints HORIZONTAL.
Click Source Link
From source file:TextSamplerDemo.java
private void addLabelTextRows(JLabel[] labels, JTextField[] textFields, GridBagLayout gridbag, Container container) {//from w w w . j a va 2s . c o m GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.EAST; int numLabels = labels.length; for (int i = 0; i < numLabels; i++) { c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last c.fill = GridBagConstraints.NONE; //reset to default c.weightx = 0.0; //reset to default container.add(labels[i], c); c.gridwidth = GridBagConstraints.REMAINDER; //end row c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; container.add(textFields[i], c); } }
From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java
public static JDialog createMessageDialog(Window parent, String title, String msg) { final JDialog dialog = new JDialog(parent, title); final JTextArea message = createMultiLineLabel(msg); final JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout()); final JPanel messagePanel = new JPanel(); messagePanel.setLayout(new GridBagLayout()); GridBagConstraints cnstrs = constraints(0, 0, true, false, GridBagConstraints.NONE); cnstrs.gridwidth = GridBagConstraints.REMAINDER; cnstrs.weighty = 0;/* w w w.j a va 2s . com*/ cnstrs.gridheight = 1; messagePanel.add(message, cnstrs); final JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); cnstrs = constraints(0, 0, true, false, GridBagConstraints.NONE); cnstrs.gridwidth = GridBagConstraints.REMAINDER; cnstrs.gridheight = 1; cnstrs.weighty = 0; cnstrs.insets = new Insets(5, 2, 5, 2); // top,left,bottom,right panel.add(messagePanel, cnstrs); cnstrs = constraints(0, 1, true, true, GridBagConstraints.HORIZONTAL); cnstrs.gridwidth = GridBagConstraints.REMAINDER; cnstrs.gridheight = 1; cnstrs.weighty = 0; cnstrs.insets = new Insets(0, 2, 10, 2); // top,left,bottom,right panel.add(buttonPanel, cnstrs); dialog.getContentPane().add(panel); dialog.pack(); return dialog; }
From source file:com.sec.ose.osi.ui.frm.main.identification.autoidentify.JPanImportSPDX.java
private JPanel getJPanelOption() { if (jPanelOption == null) { jPanelOption = new JPanel(); jPanelOption.setLayout(new GridBagLayout()); GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.gridx = 0;//from w w w . jav a2 s. c om gridBagConstraints.gridy = 0; gridBagConstraints.insets = new Insets(0, 5, 0, 5); jPanelOption.add(getJCheckSamePath(), gridBagConstraints); } return jPanelOption; }
From source file:biomine.bmvis2.crawling.CrawlSuggestionList.java
public CrawlSuggestionList() { // setMinimumSize(new Dimension(600,200)); // initialize layout GridBagLayout layout = new GridBagLayout(); this.setLayout(layout); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1;//from w w w. j a v a2 s. co m c.weighty = 0; c.gridx = 0; c.gridy = 0; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = 1; c.gridheight = 1; dbSelect = new JComboBox(); for (String db : Databases.getDatabases()) { dbSelect.addItem(db); } dbSelect.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { suggestionQuery.setDb(dbSelect.getSelectedItem().toString()); } }); this.add(dbSelect, c); c.gridy++; this.add(query, c); c.gridwidth = 1; c.weighty = 3; c.weightx = 10; c.fill = GridBagConstraints.BOTH; c.gridx = 0; c.gridy++; // listScroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); listScroller = new JScrollPane(list); this.add(listScroller, c); c.weighty = 0; c.weightx = 10; c.gridwidth = 1; c.gridx = 0; c.gridy++; this.add(new JLabel("Selected nodes:"), c); c.weighty = 3; c.weightx = 10; c.gridwidth = 1; c.gridx = 0; c.gridy++; JScrollPane selectedScroller = new JScrollPane(selectedList); this.add(selectedScroller, c); // initialize components back.setAction(new AbstractAction("< back to unfiltered results") { public void actionPerformed(ActionEvent arg0) { suggestionQuery.back(); updateList(); } }); query.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent arg0) { updateList(); } }); list.setModel(new SuggestListModel()); list.addMouseListener(new SuggestMouseListener(list)); list.addMouseMotionListener(new SuggestMouseListener(list)); list.setCellRenderer(new SuggestCellRenderer()); selectedList.setModel(new SelectedListModel()); selectedList.addMouseListener(new SuggestMouseListener(selectedList)); selectedList.addMouseMotionListener(new SuggestMouseListener(selectedList)); selectedList.setCellRenderer(new SuggestCellRenderer()); }
From source file:com.vgi.mafscaling.LogPlay.java
private void createSelectionPanel(JPanel panel) { JPanel selectionPanel = new JPanel(); GridBagLayout gbl_selectionPanel = new GridBagLayout(); gbl_selectionPanel.columnWidths = new int[] { 0, 0, 0, 0, 0, 0, 0 }; gbl_selectionPanel.rowHeights = new int[] { 0 }; gbl_selectionPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; gbl_selectionPanel.rowWeights = new double[] { 0.0 }; selectionPanel.setLayout(gbl_selectionPanel); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = insets3;// w ww . j av a 2s . c o m gbc.anchor = GridBagConstraints.WEST; gbc.gridx = 0; gbc.gridy = 0; selectionPanel.add(new JLabel("X-Axis"), gbc); gbc.gridx++; xAxisColumn = new JComboBox<String>(); selectionPanel.add(xAxisColumn, gbc); gbc.gridx++; selectionPanel.add(new JLabel("Y-Axis"), gbc); gbc.gridx++; yAxisColumn = new JComboBox<String>(); selectionPanel.add(yAxisColumn, gbc); gbc.gridx++; selectionPanel.add(new JLabel("Data*"), gbc); gbc.gridx++; zAxisColumn = new JComboBox<String>(); selectionPanel.add(zAxisColumn, gbc); gbc.gridx++; gbc.weightx = 1.0; newPlayButton = new JButton("New Play Table"); newPlayButton.addActionListener(this); selectionPanel.add(newPlayButton, gbc); xAxisColumn.addItem(""); yAxisColumn.addItem(""); zAxisColumn.addItem("Optional"); for (int i = 0; i < logDataTable.getColumnCount(); ++i) { String colName = logDataTable.getColumn(i).getHeaderValue().toString(); xAxisColumn.addItem(colName); yAxisColumn.addItem(colName); zAxisColumn.addItem(colName); } zAxisColumn.setSelectedIndex(0); gbc.insets = insets0; gbc.gridx = 0; gbc.anchor = GridBagConstraints.PAGE_START; gbc.fill = GridBagConstraints.HORIZONTAL; panel.add(selectionPanel, gbc); }
From source file:org.openconcerto.task.TodoListPanel.java
public TodoListPanel() { this.setOpaque(false); this.iconTache = new ImageIcon(TodoListPanel.class.getResource("tache.png")); this.iconPriorite = new ImageIcon(TodoListPanel.class.getResource("priorite.png")); this.userTableCellRenderer = new UserTableCellRenderer(); this.timestampTableCellRendererCreated = new TimestampTableCellRenderer(); this.timestampTableCellRendererDone = new TimestampTableCellRenderer(); this.timestampTableCellRendererDeadLine = new TimestampTableCellRenderer(true); this.timestampTableCellEditorCreated = new TimestampTableCellEditor(); this.timestampTableCellEditorDone = new TimestampTableCellEditor(); this.timestampTableCellEditorDeadLine = new TimestampTableCellEditor(); // Icon renderer List<URL> l = new Vector<URL>(); l.add(TodoListPanel.class.getResource("empty.png")); l.add(TodoListPanel.class.getResource("high.png")); l.add(TodoListPanel.class.getResource("normal.png")); l.add(TodoListPanel.class.getResource("low.png")); this.iconEditor = new IconTableCellRenderer(l); this.iconRenderer = new IconTableCellRenderer(l); final User currentUser = UserManager.getInstance().getCurrentUser(); this.model = new TodoListModel(currentUser); this.sorter = new TableSorter(this.model); this.t = new LightEventJTable(this.sorter) { public JToolTip createToolTip() { return new JMultiLineToolTip(); }//from w ww . j a v a2 s . c o m @Override public String getToolTipText(MouseEvent event) { String r = null; TodoListElement task = getTaskAt(event.getPoint()); if (task != null && task.getCreatorId() > 1) { final String comment = task.getComment(); if (comment != null) { r = comment; r += "\n\n"; } else { r = ""; } r += getTM().trM("assignedBy", "user", UserManager.getInstance().getUser(task.getCreatorId()).getFullName(), "date", task.getDate()); } return r; } }; this.sorter.setTableHeader(this.t.getTableHeader()); this.model.setTable(this.t); this.comboUser = new JMenu(TM.tr("showTaskAssignedTo")); initViewableUsers(currentUser); // L'utilisateur courant doit voir ses taches + toutes les taches dont il a les droits this.model.addIdListenerSilently(Integer.valueOf(currentUser.getId())); final int size = this.users.size(); for (int i = 0; i < size; i++) { Integer id = Integer.valueOf((this.users.get(i)).getId()); if (this.model.listenToId(id)) { ((JCheckBoxMenuItem) this.comboUser.getMenuComponent(i)).setState(true); } else { ((JCheckBoxMenuItem) this.comboUser.getMenuComponent(i)).setState(false); } } this.addButton = new JButton(TM.tr("addTask")); this.removeButton = new JButton(); this.removeButton.setOpaque(false); updateDeleteBtn(); this.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 1, 2); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 0; c.gridwidth = 6; // SEP TitledSeparator sep = new TitledSeparator( currentUser.getFirstName() + " " + currentUser.getName().toUpperCase()); this.add(sep, c); c.gridwidth = 1; c.gridx = 0; c.gridy++; c.weightx = 0; this.add(this.addButton, c); c.gridx++; this.add(this.removeButton, c); c.anchor = GridBagConstraints.EAST; c.gridx++; final JMenuBar b = new JMenuBar(); b.setOpaque(false); b.setBorderPainted(false); b.add(this.comboUser); // Pour que le menu ne disparaisse pas quand on rapetisse trop la fenetre en bas b.setMinimumSize(b.getPreferredSize()); this.add(b, c); c.gridx++; c.weightx = 1; this.detailCheckBox = new JCheckBox(TM.tr("showDetails")); this.detailCheckBox.setOpaque(false); this.detailCheckBox.setSelected(false); this.add(this.detailCheckBox, c); // c.gridx++; this.hideOldCheckBox = new JCheckBox(TM.tr("hideHistory")); this.hideOldCheckBox.setOpaque(false); this.hideOldCheckBox.setSelected(true); this.add(this.hideOldCheckBox, c); c.gridx++; c.weightx = 0; c.anchor = GridBagConstraints.EAST; this.reloadPanel.setOpaque(false); this.add(this.reloadPanel, c); // Table c.gridwidth = 6; c.gridx = 0; c.gridy++; c.fill = GridBagConstraints.BOTH; c.weighty = 1; c.weightx = 1; initPopUp(); initTable(TodoListModel.SIMPLE_MODE); this.add(new JScrollPane(this.t), c); initListeners(); this.model.asynchronousFill(); }
From source file:de.codesourcery.jasm16.ide.ui.views.EmulationOptionsView.java
private JPanel createPanel() { final JPanel result = new JPanel(); result.setLayout(new GridBagLayout()); // 'Memory protection' checkbox int y = 0;// www.j av a 2 s .c om GridBagConstraints cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL); cnstrs.gridwidth = 2; result.add(box1, cnstrs); cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL); cnstrs.gridwidth = 2; result.add(box2, cnstrs); cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL); cnstrs.gridwidth = 2; result.add(box3, cnstrs); cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL); cnstrs.gridwidth = 2; result.add(box8, cnstrs); cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL); cnstrs.gridwidth = 2; result.add(box4, cnstrs); cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL); cnstrs.gridwidth = 2; result.add(box5, cnstrs); cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL); cnstrs.gridwidth = 2; result.add(box6, cnstrs); cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL); cnstrs.gridwidth = 2; result.add(box7, cnstrs); cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL); cnstrs.gridwidth = 2; result.add(diskDrivePanel, cnstrs); cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL); cnstrs.gridwidth = 2; result.add(emulatorPanel, cnstrs); // cancel button cnstrs = constraints(0, y, false, false, GridBagConstraints.NONE); cnstrs.weightx = 0.33; cnstrs.anchor = GridBagConstraints.CENTER; final JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onCancel(); } }); result.add(cancelButton, cnstrs); // save button cnstrs = constraints(1, y, true, false, GridBagConstraints.NONE); cnstrs.weightx = 0.33; cnstrs.anchor = GridBagConstraints.CENTER; final JButton saveButton = new JButton("Save"); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final EmulationOptions options = new EmulationOptions(); saveChangesTo(options); onSave(options); } }); result.add(saveButton, cnstrs); return result; }
From source file:com._17od.upm.gui.AccountDialog.java
public AccountDialog(AccountInformation account, JFrame parentWindow, boolean readOnly, ArrayList existingAccounts) { super(parentWindow, true); boolean addingAccount = false; //Request focus on Account JDialog when mouse clicked this.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 1) { requestFocus();//w ww. jav a2 s . c o m } } }); // Set the title based on weather we've been opened in readonly mode and // weather the // Account passed in is empty or not String title = null; if (readOnly) { title = Translator.translate("viewAccount"); } else if (!readOnly && account.getAccountName().trim().equals("")) { title = Translator.translate("addAccount"); addingAccount = true; } else { title = Translator.translate("editAccount"); } setTitle(title); this.pAccount = account; this.existingAccounts = existingAccounts; this.parentWindow = parentWindow; getContentPane().setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); Container container = getContentPane(); // The AccountName Row JLabel accountLabel = new JLabel(Translator.translate("account")); c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; container.add(accountLabel, c); // This panel will hold the Account field and the copy and paste // buttons. JPanel accountPanel = new JPanel(new GridBagLayout()); accountName = new JTextField(new String(pAccount.getAccountName()), 20); if (readOnly) { accountName.setEditable(false); } c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; accountPanel.add(accountName, c); accountName.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { accountName.selectAll(); } }); JButton acctCopyButton = new JButton(); acctCopyButton.setIcon(Util.loadImage("copy-icon.png")); acctCopyButton.setToolTipText("Copy"); acctCopyButton.setEnabled(true); acctCopyButton.setMargin(new Insets(0, 0, 0, 0)); acctCopyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { copyTextField(accountName); } }); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; accountPanel.add(acctCopyButton, c); JButton acctPasteButton = new JButton(); acctPasteButton.setIcon(Util.loadImage("paste-icon.png")); acctPasteButton.setToolTipText("Paste"); acctPasteButton.setEnabled(!readOnly); acctPasteButton.setMargin(new Insets(0, 0, 0, 0)); acctPasteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { pasteToTextField(accountName); } }); c.gridx = 2; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; accountPanel.add(acctPasteButton, c); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; container.add(accountPanel, c); // Userid Row JLabel useridLabel = new JLabel(Translator.translate("userid")); c.gridx = 0; c.gridy = 1; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; container.add(useridLabel, c); // This panel will hold the User ID field and the copy and paste // buttons. JPanel idPanel = new JPanel(new GridBagLayout()); userId = new JTextField(new String(pAccount.getUserId()), 20); if (readOnly) { userId.setEditable(false); } c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; idPanel.add(userId, c); userId.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { userId.selectAll(); } }); JButton idCopyButton = new JButton(); idCopyButton.setIcon(Util.loadImage("copy-icon.png")); idCopyButton.setToolTipText("Copy"); idCopyButton.setEnabled(true); idCopyButton.setMargin(new Insets(0, 0, 0, 0)); idCopyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { copyTextField(userId); } }); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; idPanel.add(idCopyButton, c); JButton idPasteButton = new JButton(); idPasteButton.setIcon(Util.loadImage("paste-icon.png")); idPasteButton.setToolTipText("Paste"); idPasteButton.setEnabled(!readOnly); idPasteButton.setMargin(new Insets(0, 0, 0, 0)); idPasteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { pasteToTextField(userId); } }); c.gridx = 2; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; idPanel.add(idPasteButton, c); c.gridx = 1; c.gridy = 1; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; container.add(idPanel, c); // Password Row JLabel passwordLabel = new JLabel(Translator.translate("password")); c.gridx = 0; c.gridy = 2; c.anchor = GridBagConstraints.FIRST_LINE_START; c.insets = new Insets(15, 10, 10, 10); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; container.add(passwordLabel, c); // This panel will hold the password, generate password button, copy and // paste buttons, and hide password checkbox JPanel passwordPanel = new JPanel(new GridBagLayout()); password = new JPasswordField(new String(pAccount.getPassword()), 20); // allow CTRL-C on the password field password.putClientProperty("JPasswordField.cutCopyAllowed", Boolean.TRUE); password.setEditable(!readOnly); password.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { password.selectAll(); } }); c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 1; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; passwordPanel.add(password, c); JButton generateRandomPasswordButton = new JButton(Translator.translate("generate")); if (readOnly) { generateRandomPasswordButton.setEnabled(false); } generateRandomPasswordButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionevent) { // Get the user's preference about including or not Escape // Characters to generated passwords Boolean includeEscapeChars = new Boolean( Preferences.get(Preferences.ApplicationOptions.INCLUDE_ESCAPE_CHARACTERS, "true")); int pwLength = Preferences.getInt(Preferences.ApplicationOptions.ACCOUNT_PASSWORD_LENGTH, 8); String Password; if ((includeEscapeChars.booleanValue()) && (pwLength > 3)) { // Verify that the generated password satisfies the criteria // for strong passwords(including Escape Characters) do { Password = GeneratePassword(pwLength, includeEscapeChars.booleanValue()); } while (!(CheckPassStrong(Password, includeEscapeChars.booleanValue()))); } else if (!(includeEscapeChars.booleanValue()) && (pwLength > 2)) { // Verify that the generated password satisfies the criteria // for strong passwords(excluding Escape Characters) do { Password = GeneratePassword(pwLength, includeEscapeChars.booleanValue()); } while (!(CheckPassStrong(Password, includeEscapeChars.booleanValue()))); } else { // Else a weak password of 3 or less chars will be produced Password = GeneratePassword(pwLength, includeEscapeChars.booleanValue()); } password.setText(Password); } }); if (addingAccount) { generateRandomPasswordButton.doClick(); } c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; passwordPanel.add(generateRandomPasswordButton, c); JButton pwCopyButton = new JButton(); pwCopyButton.setIcon(Util.loadImage("copy-icon.png")); pwCopyButton.setToolTipText("Copy"); pwCopyButton.setEnabled(true); pwCopyButton.setMargin(new Insets(0, 0, 0, 0)); pwCopyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { copyTextField(password); } }); c.gridx = 2; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; passwordPanel.add(pwCopyButton, c); JButton pwPasteButton = new JButton(); pwPasteButton.setIcon(Util.loadImage("paste-icon.png")); pwPasteButton.setToolTipText("Paste"); pwPasteButton.setEnabled(!readOnly); pwPasteButton.setMargin(new Insets(0, 0, 0, 0)); pwPasteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { pasteToTextField(password); } }); c.gridx = 3; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; passwordPanel.add(pwPasteButton, c); JCheckBox hidePasswordCheckbox = new JCheckBox(Translator.translate("hide"), true); defaultEchoChar = password.getEchoChar(); hidePasswordCheckbox.setMargin(new Insets(5, 0, 5, 0)); hidePasswordCheckbox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { password.setEchoChar(defaultEchoChar); } else { password.setEchoChar((char) 0); } } }); Boolean hideAccountPassword = new Boolean( Preferences.get(Preferences.ApplicationOptions.ACCOUNT_HIDE_PASSWORD, "true")); hidePasswordCheckbox.setSelected(hideAccountPassword.booleanValue()); c.gridx = 0; c.gridy = 1; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 0); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; passwordPanel.add(hidePasswordCheckbox, c); c.gridx = 1; c.gridy = 2; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 1; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; container.add(passwordPanel, c); // URL Row JLabel urlLabel = new JLabel(Translator.translate("url")); c.gridx = 0; c.gridy = 3; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; container.add(urlLabel, c); // This panel will hold the URL field and the copy and paste buttons. JPanel urlPanel = new JPanel(new GridBagLayout()); url = new JTextField(new String(pAccount.getUrl()), 20); if (readOnly) { url.setEditable(false); } c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; urlPanel.add(url, c); url.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { url.selectAll(); } }); final JButton urlLaunchButton = new JButton(); urlLaunchButton.setIcon(Util.loadImage("launch-url-sm.png")); urlLaunchButton.setToolTipText("Launch URL"); urlLaunchButton.setEnabled(true); urlLaunchButton.setMargin(new Insets(0, 0, 0, 0)); urlLaunchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { String urlText = url.getText(); // Check if the selected url is null or emty and inform the user // via JoptioPane message if ((urlText == null) || (urlText.length() == 0)) { JOptionPane.showMessageDialog(urlLaunchButton.getParent(), Translator.translate("EmptyUrlJoptionpaneMsg"), Translator.translate("UrlErrorJoptionpaneTitle"), JOptionPane.WARNING_MESSAGE); // Check if the selected url is a valid formated url(via // urlIsValid() method) and inform the user via JoptioPane // message } else if (!(urlIsValid(urlText))) { JOptionPane.showMessageDialog(urlLaunchButton.getParent(), Translator.translate("InvalidUrlJoptionpaneMsg"), Translator.translate("UrlErrorJoptionpaneTitle"), JOptionPane.WARNING_MESSAGE); // Call the method LaunchSelectedURL() using the selected // url as input } else { LaunchSelectedURL(urlText); } } }); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; urlPanel.add(urlLaunchButton, c); JButton urlCopyButton = new JButton(); urlCopyButton.setIcon(Util.loadImage("copy-icon.png")); urlCopyButton.setToolTipText("Copy"); urlCopyButton.setEnabled(true); urlCopyButton.setMargin(new Insets(0, 0, 0, 0)); urlCopyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { copyTextField(url); } }); c.gridx = 2; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; urlPanel.add(urlCopyButton, c); JButton urlPasteButton = new JButton(); urlPasteButton.setIcon(Util.loadImage("paste-icon.png")); urlPasteButton.setToolTipText("Paste"); urlPasteButton.setEnabled(!readOnly); urlPasteButton.setMargin(new Insets(0, 0, 0, 0)); urlPasteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { pasteToTextField(url); } }); c.gridx = 3; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; urlPanel.add(urlPasteButton, c); c.gridx = 1; c.gridy = 3; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; container.add(urlPanel, c); // Notes Row JLabel notesLabel = new JLabel(Translator.translate("notes")); c.gridx = 0; c.gridy = 4; c.anchor = GridBagConstraints.FIRST_LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; container.add(notesLabel, c); // This panel will hold the Notes text area and the copy and paste // buttons. JPanel notesPanel = new JPanel(new GridBagLayout()); notes = new JTextArea(new String(pAccount.getNotes()), 10, 20); if (readOnly) { notes.setEditable(false); } notes.setLineWrap(true); // Enable line wrapping. notes.setWrapStyleWord(true); // Line wrap at whitespace. JScrollPane notesScrollPane = new JScrollPane(notes); c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.BOTH; notesPanel.add(notesScrollPane, c); JButton notesCopyButton = new JButton(); notesCopyButton.setIcon(Util.loadImage("copy-icon.png")); notesCopyButton.setToolTipText("Copy"); notesCopyButton.setEnabled(true); notesCopyButton.setMargin(new Insets(0, 0, 0, 0)); notesCopyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { copyTextArea(notes); } }); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.FIRST_LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; notesPanel.add(notesCopyButton, c); JButton notesPasteButton = new JButton(); notesPasteButton.setIcon(Util.loadImage("paste-icon.png")); notesPasteButton.setToolTipText("Paste"); notesPasteButton.setEnabled(!readOnly); notesPasteButton.setMargin(new Insets(0, 0, 0, 0)); notesPasteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { pasteToTextArea(notes); } }); c.gridx = 2; c.gridy = 0; c.anchor = GridBagConstraints.FIRST_LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; notesPanel.add(notesPasteButton, c); c.gridx = 1; c.gridy = 4; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; container.add(notesPanel, c); // Seperator Row JSeparator sep = new JSeparator(); c.gridx = 0; c.gridy = 5; c.anchor = GridBagConstraints.PAGE_END; c.insets = new Insets(0, 0, 0, 0); c.weightx = 0; c.weighty = 0; c.gridwidth = 3; c.fill = GridBagConstraints.HORIZONTAL; container.add(sep, c); // Button Row JPanel buttonPanel = new JPanel(); JButton okButton = new JButton(Translator.translate("ok")); // Link Enter key to okButton getRootPane().setDefaultButton(okButton); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okButtonAction(); } }); buttonPanel.add(okButton); if (!readOnly) { JButton cancelButton = new JButton(Translator.translate("cancel")); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { closeButtonAction(); } }); buttonPanel.add(cancelButton); } c.gridx = 0; c.gridy = 6; c.anchor = GridBagConstraints.PAGE_END; c.insets = new Insets(5, 0, 5, 0); c.weightx = 0; c.weighty = 0; c.gridwidth = 3; c.fill = GridBagConstraints.NONE; container.add(buttonPanel, c); }
From source file:org.languagetool.gui.ConfigurationDialog.java
public boolean show(List<Rule> rules) { configChanged = false;/*www. j a v a 2s.c o m*/ if (original != null) { config.restoreState(original); } dialog = new JDialog(owner, true); dialog.setTitle(messages.getString("guiConfigWindowTitle")); // close dialog when user presses Escape key: KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(@SuppressWarnings("unused") ActionEvent actionEvent) { dialog.setVisible(false); } }; JRootPane rootPane = dialog.getRootPane(); rootPane.registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); configurableRules.clear(); Language lang = config.getLanguage(); if (lang == null) { lang = Languages.getLanguageForLocale(Locale.getDefault()); } String specialTabNames[] = config.getSpecialTabNames(); int numConfigTrees = 2 + specialTabNames.length; configTree = new JTree[numConfigTrees]; JPanel checkBoxPanel[] = new JPanel[numConfigTrees]; DefaultMutableTreeNode rootNode; GridBagConstraints cons; for (int i = 0; i < numConfigTrees; i++) { checkBoxPanel[i] = new JPanel(); cons = new GridBagConstraints(); checkBoxPanel[i].setLayout(new GridBagLayout()); cons.anchor = GridBagConstraints.NORTHWEST; cons.gridx = 0; cons.weightx = 1.0; cons.weighty = 1.0; cons.fill = GridBagConstraints.HORIZONTAL; Collections.sort(rules, new CategoryComparator()); if (i == 0) { rootNode = createTree(rules, false, null); // grammar options } else if (i == 1) { rootNode = createTree(rules, true, null); // Style options } else { rootNode = createTree(rules, true, specialTabNames[i - 2]); // Special tab options } configTree[i] = new JTree(getTreeModel(rootNode)); configTree[i].applyComponentOrientation(ComponentOrientation.getOrientation(lang.getLocale())); configTree[i].setRootVisible(false); configTree[i].setEditable(false); configTree[i].setCellRenderer(new CheckBoxTreeCellRenderer()); TreeListener.install(configTree[i]); checkBoxPanel[i].add(configTree[i], cons); configTree[i].addMouseListener(getMouseAdapter()); } JPanel portPanel = new JPanel(); portPanel.setLayout(new GridBagLayout()); cons = new GridBagConstraints(); cons.insets = new Insets(0, 4, 0, 0); cons.gridx = 0; cons.gridy = 0; cons.anchor = GridBagConstraints.WEST; cons.fill = GridBagConstraints.NONE; cons.weightx = 0.0f; if (!insideOffice) { createNonOfficeElements(cons, portPanel); } else { createOfficeElements(cons, portPanel); } JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new GridBagLayout()); JButton okButton = new JButton(Tools.getLabel(messages.getString("guiOKButton"))); okButton.setMnemonic(Tools.getMnemonic(messages.getString("guiOKButton"))); okButton.setActionCommand(ACTION_COMMAND_OK); okButton.addActionListener(this); JButton cancelButton = new JButton(Tools.getLabel(messages.getString("guiCancelButton"))); cancelButton.setMnemonic(Tools.getMnemonic(messages.getString("guiCancelButton"))); cancelButton.setActionCommand(ACTION_COMMAND_CANCEL); cancelButton.addActionListener(this); cons = new GridBagConstraints(); cons.insets = new Insets(0, 4, 0, 0); buttonPanel.add(okButton, cons); buttonPanel.add(cancelButton, cons); JTabbedPane tabpane = new JTabbedPane(); JPanel jPane = new JPanel(); jPane.setLayout(new GridBagLayout()); cons = new GridBagConstraints(); cons.insets = new Insets(4, 4, 4, 4); cons.gridx = 0; cons.gridy = 0; cons.weightx = 10.0f; cons.weighty = 0.0f; cons.fill = GridBagConstraints.NONE; cons.anchor = GridBagConstraints.NORTHWEST; cons.gridy++; cons.anchor = GridBagConstraints.WEST; jPane.add(getMotherTonguePanel(cons), cons); if (insideOffice) { cons.gridy += 3; } else { cons.gridy++; } cons.anchor = GridBagConstraints.WEST; jPane.add(getNgramPanel(cons), cons); cons.gridy++; cons.anchor = GridBagConstraints.WEST; jPane.add(getWord2VecPanel(cons), cons); cons.gridy++; cons.anchor = GridBagConstraints.WEST; jPane.add(portPanel, cons); cons.fill = GridBagConstraints.HORIZONTAL; cons.anchor = GridBagConstraints.WEST; for (JPanel extra : extraPanels) { //in case it wasn't in a containment hierarchy when user changed L&F SwingUtilities.updateComponentTreeUI(extra); cons.gridy++; jPane.add(extra, cons); } cons.gridy++; cons.fill = GridBagConstraints.BOTH; cons.weighty = 1.0f; jPane.add(new JPanel(), cons); tabpane.addTab(messages.getString("guiGeneral"), jPane); jPane = new JPanel(); jPane.setLayout(new GridBagLayout()); cons = new GridBagConstraints(); cons.insets = new Insets(4, 4, 4, 4); cons.gridx = 0; cons.gridy = 0; cons.weightx = 10.0f; cons.weighty = 10.0f; cons.fill = GridBagConstraints.BOTH; jPane.add(new JScrollPane(checkBoxPanel[0]), cons); cons.weightx = 0.0f; cons.weighty = 0.0f; cons.gridx = 0; cons.gridy++; cons.fill = GridBagConstraints.NONE; cons.anchor = GridBagConstraints.LINE_END; jPane.add(getTreeButtonPanel(0), cons); tabpane.addTab(messages.getString("guiGrammarRules"), jPane); jPane = new JPanel(); jPane.setLayout(new GridBagLayout()); cons = new GridBagConstraints(); cons.insets = new Insets(4, 4, 4, 4); cons.gridx = 0; cons.gridy = 0; cons.weightx = 10.0f; cons.weighty = 10.0f; cons.fill = GridBagConstraints.BOTH; jPane.add(new JScrollPane(checkBoxPanel[1]), cons); cons.weightx = 0.0f; cons.weighty = 0.0f; cons.gridx = 0; cons.gridy++; cons.fill = GridBagConstraints.NONE; cons.anchor = GridBagConstraints.LINE_END; jPane.add(getTreeButtonPanel(1), cons); cons.gridx = 0; cons.gridy++; cons.weightx = 5.0f; cons.weighty = 5.0f; cons.fill = GridBagConstraints.BOTH; cons.anchor = GridBagConstraints.WEST; jPane.add(new JScrollPane(getSpecialRuleValuePanel()), cons); tabpane.addTab(messages.getString("guiStyleRules"), jPane); for (int i = 0; i < specialTabNames.length; i++) { jPane = new JPanel(); jPane.setLayout(new GridBagLayout()); cons = new GridBagConstraints(); cons.insets = new Insets(4, 4, 4, 4); cons.gridx = 0; cons.gridy = 0; cons.weightx = 10.0f; cons.weighty = 10.0f; cons.fill = GridBagConstraints.BOTH; jPane.add(new JScrollPane(checkBoxPanel[i + 2]), cons); cons.weightx = 0.0f; cons.weighty = 0.0f; cons.gridx = 0; cons.gridy++; cons.fill = GridBagConstraints.NONE; cons.anchor = GridBagConstraints.LINE_END; jPane.add(getTreeButtonPanel(i + 2), cons); tabpane.addTab(specialTabNames[i], jPane); } jPane = new JPanel(); jPane.setLayout(new GridBagLayout()); cons = new GridBagConstraints(); cons.insets = new Insets(4, 4, 4, 4); cons.gridx = 0; cons.gridy = 0; if (insideOffice) { JLabel versionText = new JLabel(messages.getString("guiUColorHint")); versionText.setForeground(Color.blue); jPane.add(versionText, cons); cons.gridy++; } cons.weightx = 2.0f; cons.weighty = 2.0f; cons.fill = GridBagConstraints.BOTH; jPane.add(new JScrollPane(getUnderlineColorPanel(rules)), cons); Container contentPane = dialog.getContentPane(); contentPane.setLayout(new GridBagLayout()); cons = new GridBagConstraints(); cons.insets = new Insets(4, 4, 4, 4); cons.gridx = 0; cons.gridy = 0; cons.weightx = 10.0f; cons.weighty = 10.0f; cons.fill = GridBagConstraints.BOTH; cons.anchor = GridBagConstraints.NORTHWEST; contentPane.add(tabpane, cons); cons.weightx = 0.0f; cons.weighty = 0.0f; cons.gridy++; cons.fill = GridBagConstraints.NONE; cons.anchor = GridBagConstraints.EAST; contentPane.add(buttonPanel, cons); dialog.pack(); // center on screen: Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = dialog.getSize(); dialog.setLocation(screenSize.width / 2 - frameSize.width / 2, screenSize.height / 2 - frameSize.height / 2); dialog.setLocationByPlatform(true); // add Color tab after dimension was set tabpane.addTab(messages.getString("guiUnderlineColor"), jPane); for (JPanel extra : this.extraPanels) { if (extra instanceof SavablePanel) { ((SavablePanel) extra).componentShowing(); } } dialog.setVisible(true); return configChanged; }
From source file:com.vgi.mafscaling.VECalc.java
protected void createGraghTab() { JPanel plotPanel = new JPanel(); add(plotPanel, "<html><div style='text-align: center;'>C<br>h<br>a<br>r<br>t</div></html>"); GridBagLayout gbl_plotPanel = new GridBagLayout(); gbl_plotPanel.columnWidths = new int[] { 0 }; gbl_plotPanel.rowHeights = new int[] { 0, 0 }; gbl_plotPanel.columnWeights = new double[] { 1.0 }; gbl_plotPanel.rowWeights = new double[] { 0.0, 1.0 }; plotPanel.setLayout(gbl_plotPanel);/*from w w w .ja va2s. co m*/ JPanel cntlPanel = new JPanel(); GridBagConstraints gbl_ctrlPanel = new GridBagConstraints(); gbl_ctrlPanel.insets = new Insets(3, 3, 3, 3); gbl_ctrlPanel.anchor = GridBagConstraints.NORTH; gbl_ctrlPanel.weightx = 1.0; gbl_ctrlPanel.fill = GridBagConstraints.HORIZONTAL; gbl_ctrlPanel.gridx = 0; gbl_ctrlPanel.gridy = 0; plotPanel.add(cntlPanel, gbl_ctrlPanel); GridBagLayout gbl_cntlPanel = new GridBagLayout(); gbl_cntlPanel.columnWidths = new int[] { 0, 0 }; gbl_cntlPanel.rowHeights = new int[] { 0, 0 }; gbl_cntlPanel.columnWeights = new double[] { 0.0, 1.0 }; gbl_cntlPanel.rowWeights = new double[] { 0 }; cntlPanel.setLayout(gbl_cntlPanel); createChart(plotPanel, xAxisName, yAxisName); }