List of usage examples for javax.swing JLabel setHorizontalAlignment
@BeanProperty(visualUpdate = true, enumerationValues = { "SwingConstants.LEFT", "SwingConstants.CENTER", "SwingConstants.RIGHT", "SwingConstants.LEADING", "SwingConstants.TRAILING" }, description = "The alignment of the label's content along the X axis.") public void setHorizontalAlignment(int alignment)
From source file:edu.harvard.i2b2.query.QueryTopPanel.java
private void jMorePanelsButtonActionPerformed(java.awt.event.ActionEvent evt) { if (dataModel.hasEmptyPanels()) { JOptionPane.showMessageDialog(this, "Please use an existing empty panel before adding a new one."); return;//from www . jav a2 s . c o m } int rightmostPosition = dataModel.lastLabelPosition(); JLabel label = new JLabel(); label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); label.setText("and"); label.setToolTipText("Click to change the relationship"); label.setBorder(javax.swing.BorderFactory.createEtchedBorder()); label.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jAndOrLabelMouseClicked(evt); } }); //jPanel1.add(label); //label.setBounds(rightmostPosition, 90, 30, 18); QueryConceptTreePanel panel = new QueryConceptTreePanel("Group " + (dataModel.getCurrentPanelCount() + 1), this); jPanel1.add(panel); panel.setBounds(rightmostPosition + 5, 0, 180, getParent().getHeight() - 100); jPanel1.setPreferredSize(new Dimension(rightmostPosition + 5 + 181, getHeight() - 100)); jScrollPane4.setViewportView(jPanel1); dataModel.addPanel(panel, label, rightmostPosition + 5 + 180); /*System.out.println(jScrollPane4.getViewport().getExtentSize().width+":"+ jScrollPane4.getViewport().getExtentSize().height); System.out.println(jScrollPane4.getHorizontalScrollBar().getVisibleRect().width+":" +jScrollPane4.getHorizontalScrollBar().getVisibleRect().height); System.out.println(jScrollPane4.getHorizontalScrollBar().getVisibleAmount()); System.out.println(jScrollPane4.getHorizontalScrollBar().getValue());*/ jScrollPane4.getHorizontalScrollBar().setValue(jScrollPane4.getHorizontalScrollBar().getMaximum()); jScrollPane4.getHorizontalScrollBar().setUnitIncrement(40); //this.jScrollPane4.removeAll(); //this.jScrollPane4.setViewportView(jPanel1); //revalidate(); //jScrollPane3.setBounds(420, 0, 170, 300); //jScrollPane4.setBounds(20, 35, 335, 220); resizePanels(getParent().getWidth(), getParent().getHeight()); }
From source file:me.philnate.textmanager.windows.MainWindow.java
/** * Initialize the contents of the frame. *///from w w w .ja va 2s.c o m private void initialize() { changeListener = new ChangeListener(); frame = new JFrame(); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { Starter.shutdown(); } }); frame.setBounds(100, 100, 1197, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new MigLayout("", "[grow]", "[][grow][::16px]")); customers = new CustomerComboBox(); customers.addItemListener(changeListener); frame.getContentPane().add(customers, "flowx,cell 0 0,growx"); jScrollPane = new JScrollPane(); billLines = new BillingItemTable(frame, true); jScrollPane.setViewportView(billLines); frame.getContentPane().add(jScrollPane, "cell 0 1,grow"); // for each file added through drag&drop create a new lineItem new FileDrop(jScrollPane, new FileDrop.Listener() { @Override public void filesDropped(File[] files) { for (File file : files) { addNewBillingItem(Document.loadAndSave(file)); } } }); monthChooser = new JMonthChooser(); monthChooser.addPropertyChangeListener(changeListener); frame.getContentPane().add(monthChooser, "cell 0 0"); yearChooser = new JYearChooser(); yearChooser.addPropertyChangeListener(changeListener); frame.getContentPane().add(yearChooser, "cell 0 0"); JButton btnAddLine = new JButton(); btnAddLine.setIcon(ImageRegistry.getImage("load.gif")); btnAddLine.setToolTipText(getCaption("mw.tooltip.add")); btnAddLine.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { addNewBillingItem(); } }); frame.getContentPane().add(btnAddLine, "cell 0 0"); JButton btnMassAdd = new JButton(); btnMassAdd.setIcon(ImageRegistry.getImage("load_all.gif")); btnMassAdd.setToolTipText(getCaption("mw.tooltip.massAdd")); btnMassAdd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { JFileChooser file = new DocXFileChooser(); switch (file.showOpenDialog(frame)) { case JFileChooser.APPROVE_OPTION: File[] files = file.getSelectedFiles(); if (null != files) { for (File fl : files) { addNewBillingItem(Document.loadAndSave(fl)); } } break; default: return; } } }); frame.getContentPane().add(btnMassAdd, "cell 0 0"); billNo = new JTextField(); // enable/disable build button based upon text in billNo billNo.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent arg0) { setButtonStates(); } @Override public void insertUpdate(DocumentEvent arg0) { setButtonStates(); } @Override public void changedUpdate(DocumentEvent arg0) { setButtonStates(); } private void setButtonStates() { boolean notBlank = StringUtils.isNotBlank(billNo.getText()); build.setEnabled(notBlank); view.setEnabled(pdf.find(billNo.getText() + ".pdf").size() == 1); } }); frame.getContentPane().add(billNo, "cell 0 0"); billNo.setColumns(10); build = new JButton(); build.setEnabled(false);// disable build Button until there's some // billNo entered build.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (runningThread == null) { try { // check that billNo isn't empty or already used within // another Bill if (billNo.getText().trim().equals("")) { JOptionPane.showMessageDialog(frame, getCaption("mw.dialog.error.billNoBlank.msg"), getCaption("mw.dialog.error.billNoBlank.title"), JOptionPane.ERROR_MESSAGE); return; } try { bill.setBillNo(billNo.getText()).save(); } catch (DuplicateKey e) { // unset the internal value as this is already used bill.setBillNo(""); JOptionPane.showMessageDialog(frame, format(getCaption("mw.error.billNoUsed.msg"), billNo.getText()), getCaption("mw.dialog.error.billNoBlank.title"), JOptionPane.ERROR_MESSAGE); return; } PDFCreator pdf = new PDFCreator(bill); pdf.addListener(new ThreadCompleteListener() { @Override public void threadCompleted(NotifyingThread notifyingThread) { build.setToolTipText(getCaption("mw.tooltip.build")); build.setIcon(ImageRegistry.getImage("build.png")); runningThread = null; view.setEnabled(DB.pdf.find(billNo.getText() + ".pdf").size() == 1); } }); runningThread = new Thread(pdf); runningThread.start(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } build.setToolTipText(getCaption("mw.tooltip.build.cancel")); build.setIcon(ImageRegistry.getImage("cancel.gif")); } else { runningThread.interrupt(); runningThread = null; build.setToolTipText(getCaption("mw.tooltip.build")); build.setIcon(ImageRegistry.getImage("build.png")); } } }); build.setToolTipText(getCaption("mw.tooltip.build")); build.setIcon(ImageRegistry.getImage("build.png")); frame.getContentPane().add(build, "cell 0 0"); view = new JButton(); view.setToolTipText(getCaption("mw.tooltip.view")); view.setIcon(ImageRegistry.getImage("view.gif")); view.setEnabled(false); view.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { File file = new File(System.getProperty("user.dir"), format("template/%s.tmp.pdf", billNo.getText())); try { pdf.findOne(billNo.getText() + ".pdf").writeTo(file); new ProcessBuilder(Setting.find("pdfViewer").getValue(), file.getAbsolutePath()).start() .waitFor(); file.delete(); } catch (IOException | InterruptedException e1) { // TODO Auto-generated catch block LOG.warn("Error while building PDF", e1); } } }); frame.getContentPane().add(view, "cell 0 0"); statusBar = new JPanel(); statusBar.setBorder(new BevelBorder(BevelBorder.LOWERED)); statusBar.setLayout(new BoxLayout(statusBar, BoxLayout.X_AXIS)); GitRepositoryState state = DB.state; JLabel statusLabel = new JLabel(String.format("textManager Version v%s build %s", state.getCommitIdDescribe(), state.getBuildTime())); statusLabel.setHorizontalAlignment(SwingConstants.LEFT); statusBar.add(statusLabel); frame.add(statusBar, "cell 0 2,growx"); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu menu = new JMenu(getCaption("mw.menu.edit")); JMenuItem itemCust = new JMenuItem(getCaption("mw.menu.edit.customer")); itemCust.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { new CustomerWindow(customers); } }); menu.add(itemCust); JMenuItem itemSetting = new JMenuItem(getCaption("mw.menu.edit.settings")); itemSetting.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { new SettingWindow(); } }); menu.add(itemSetting); JMenuItem itemImport = new JMenuItem(getCaption("mw.menu.edit.import")); itemImport.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { new ImportWindow(new ImportListener() { @Override public void entriesImported(List<BillingItem> items) { for (BillingItem item : items) { item.setCustomerId(customers.getSelectedCustomer().getId()) .setMonth(monthChooser.getMonth()).setYear(yearChooser.getYear()); item.save(); billLines.addRow(item); } } }, frame); } }); menu.add(itemImport); menuBar.add(menu); customers.loadCustomer(); fillTableModel(); }
From source file:com.francetelecom.rd.dashboard.pc.DashboardPC.java
private void initDashboardWithRules() { // get existing rules and display them try {//from ww w . j av a 2 s. c om Rule[] ruleList = busConnector.getAllRules(); for (int i = 0; i < ruleList.length; i++) { if (!ruleList[i].isPrivate()) addRulePanelToDashboard(ruleList[i].getId()); } } catch (HomeBusException e) { logger.error("Could not retrieve bus rules : " + e.getMessage()); e.printStackTrace(); } // small add rule panel init JPanel panelAddRule = new JPanel(); panelAddRule.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); panelAddRule.setLayout(null); JLabel addRuleLbl = new JLabel("Configure new rule"); addRuleLbl.setHorizontalAlignment(SwingConstants.CENTER); addRuleLbl.setForeground(new Color(169, 169, 169)); addRuleLbl.setFont(new Font("Arial", Font.BOLD, 13)); addRuleLbl.setBounds(10, 25, 229, 27); panelAddRule.add(addRuleLbl); JButton addRuleBtn = new JButton("+"); addRuleBtn.setForeground(new Color(128, 128, 128)); addRuleBtn.setBounds(100, 57, 41, 23); panelAddRule.add(addRuleBtn); rulesContent.add(panelAddRule); myRulePanelMap.put("0", panelAddRule); updateRuleListDisplay(); // add panel elements : photo, service friendly name, IF label, condition parameter JPanel panelRule1 = new JPanel(); panelRule1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); panelRule1.setLayout(null); JPanel rulePanelServicePhoto1 = new JPanel(); rulePanelServicePhoto1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); rulePanelServicePhoto1.setBounds(10, 16, 27, 27); panelRule1.add(rulePanelServicePhoto1); String serviceName1 = "Visio TV"; JLabel ruleLblServiceName1 = new JLabel(serviceName1); ruleLblServiceName1.setFont(new Font("Arial", Font.BOLD, 15)); ruleLblServiceName1.setForeground(new Color(100, 149, 237)); ruleLblServiceName1.setBounds(47, 11, 212, 18); panelRule1.add(ruleLblServiceName1); String serviceDeviceOwner1 = "Set-top Box"; JLabel ruleLblOnDevice1 = new JLabel("on " + serviceDeviceOwner1); ruleLblOnDevice1.setForeground(Color.GRAY); ruleLblOnDevice1.setFont(new Font("Arial", Font.PLAIN, 11)); ruleLblOnDevice1.setBounds(47, 29, 212, 14); panelRule1.add(ruleLblOnDevice1); JLabel ruleLblIf1 = new JLabel("IF"); ruleLblIf1.setForeground(Color.GRAY); ruleLblIf1.setFont(new Font("Arial", Font.BOLD, 30)); ruleLblIf1.setBounds(10, 49, 27, 35); panelRule1.add(ruleLblIf1); // condition String condition1 = "IncomingVoIP" + " = " + "true"; JLabel ruleLblConditionParam1 = new JLabel(condition1); ruleLblConditionParam1.setFont(new Font("Arial", Font.BOLD, 13)); ruleLblConditionParam1.setForeground(Color.GRAY); ruleLblConditionParam1.setBounds(47, 49, 192, 35); panelRule1.add(ruleLblConditionParam1); myRulePanelMap.put("1", panelRule1); rulesContent.add(panelRule1); // add panel elements : photo, service friendly name, IF label, condition parameter JPanel panelRule2 = new JPanel(); panelRule2.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); panelRule2.setLayout(null); JPanel rulePanelServicePhoto2 = new JPanel(); rulePanelServicePhoto2.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); rulePanelServicePhoto2.setBounds(10, 16, 27, 27); panelRule2.add(rulePanelServicePhoto2); String serviceName2 = "Wi-Fi Off"; JLabel ruleLblServiceName2 = new JLabel(serviceName2); ruleLblServiceName2.setFont(new Font("Arial", Font.BOLD, 15)); ruleLblServiceName2.setForeground(new Color(100, 149, 237)); ruleLblServiceName2.setBounds(47, 11, 212, 18); panelRule2.add(ruleLblServiceName2); String serviceDeviceOwner2 = "Livebox"; JLabel ruleLblOnDevice2 = new JLabel("on " + serviceDeviceOwner2); ruleLblOnDevice2.setForeground(Color.GRAY); ruleLblOnDevice2.setFont(new Font("Arial", Font.PLAIN, 11)); ruleLblOnDevice2.setBounds(47, 29, 212, 14); panelRule2.add(ruleLblOnDevice2); JLabel ruleLblIf2 = new JLabel("IF"); ruleLblIf2.setForeground(Color.GRAY); ruleLblIf2.setFont(new Font("Arial", Font.BOLD, 30)); ruleLblIf2.setBounds(10, 49, 27, 35); panelRule2.add(ruleLblIf2); // condition String condition2 = "Absence" + " = " + "true"; JLabel ruleLblConditionParam2 = new JLabel(condition2); ruleLblConditionParam2.setFont(new Font("Arial", Font.BOLD, 13)); ruleLblConditionParam2.setForeground(Color.GRAY); ruleLblConditionParam2.setBounds(47, 49, 192, 35); panelRule2.add(ruleLblConditionParam2); myRulePanelMap.put("2", panelRule2); rulesContent.add(panelRule2); updateRuleListDisplay(); busConnector.addRuleDefinitionsListener(this); }
From source file:com.sshtools.appframework.api.ui.SshToolsApplicationPanel.java
/** * Display something other that the normal blank screen so our component * looks pretty.//w w w . ja va 2 s. co m */ protected void showWelcomeScreen() { synchronized (getTreeLock()) { removeAll(); setLayout(new BorderLayout()); // GradientPanel p = new GradientPanel(new BorderLayout()); // p.setBackground(Color.white); // p.setBackground2(new Color(164, 228, 244)); // p.setForeground(Color.black); JPanel p = new JPanel(new BorderLayout()); JLabel welcomeLabel = new JLabel("", JLabel.CENTER); welcomeLabel.setForeground(Color.white); welcomeLabel.setFont(welcomeLabel.getFont().deriveFont(72f).deriveFont(Font.BOLD + Font.ITALIC)); welcomeLabel.setHorizontalAlignment(JLabel.RIGHT); p.add(welcomeLabel, BorderLayout.SOUTH); add(p, BorderLayout.CENTER); validate(); } }
From source file:com.diversityarrays.kdxplore.field.PlotIdTrialLayoutPane.java
@Override public JComponent getFieldLayoutPane(FieldLayout<Integer>[] returnLayout) { int runLength = runLengthModel.getNumber().intValue(); if (runLength <= 0) { fieldLayoutRunLengthLE_0.setText("RunLength=" + runLength); return fieldLayoutRunLengthLE_0; }/*from w ww . j a v a 2 s . c o m*/ int firstPlotId = plotIdModel.getNumber().intValue(); PlotIdFieldLayoutProcessor layoutProcessor = new PlotIdFieldLayoutProcessor(); FieldLayout<Integer> fieldLayout = layoutProcessor.layoutField(plotIdentSummary, odtPanel.getOrigin(), firstPlotId, odtPanel.getOrientation(), runLength, odtPanel.getTraversal()); if (returnLayout != null && returnLayout.length > 0) { returnLayout[0] = fieldLayout; } Border insideBorder = new LineBorder(Color.BLACK); Border outsideBorder = new EmptyBorder(1, 1, 1, 1); Border border = new CompoundBorder(outsideBorder, insideBorder); GridLayout gridLayout = new GridLayout(fieldLayout.ysize, fieldLayout.xsize); if (DEBUG) { System.out.println( "GridLayout( rows=" + gridLayout.getRows() + " , cols=" + gridLayout.getColumns() + ")"); } fieldLayoutRunLengthGT_0.setLayout(gridLayout); fieldLayoutRunLengthGT_0.removeAll(); for (int y = 0; y < fieldLayout.ysize; ++y) { for (int x = 0; x < fieldLayout.xsize; ++x) { Integer plotId = fieldLayout.cells[y][x]; String label_s; if (plotId == null) { label_s = "."; } else { PlotName plotName = plotNameByPlotId.get(plotId); if (plotName == null) { label_s = "-"; } else { //s = "P_" + plotId + ":" + x + "," + y; StringBuilder sb = new StringBuilder("P_"); sb.append(plotName.getPlotId()); Integer xx = plotName.getX(); Integer yy = plotName.getY(); if (xx != null || yy != null) { sb.append(": "); if (xx != null) { sb.append(xx); } sb.append(","); if (yy != null) { sb.append(yy); } } label_s = sb.toString(); } } JLabel label = new JLabel("<HTML><BR>" + label_s + "<BR> "); label.setHorizontalAlignment(SwingConstants.CENTER); label.setBorder(border); fieldLayoutRunLengthGT_0.add(label); } } return fieldLayoutRunLengthGT_0; }
From source file:com.polivoto.vistas.Charts.java
public void getBotonesPreguntas(JPanel botones) { GridBagConstraints gridBagConstraints; boolean first = false; botones.removeAll();/* w ww .j a v a 2 s. c o m*/ JPanel panelRelleno = new JPanel(new BorderLayout(20, 20)); panelRelleno.setBackground(Color.white); JPanel panelContainer = new JPanel(new GridLayout(0, 1, 30, 30)); panelContainer.setBackground(Color.white); botones.setPreferredSize(new Dimension(250, 0)); botones.setLayout(new GridBagLayout()); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; gridBagConstraints.weighty = 0.1; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); botones.add(panelContainer, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; gridBagConstraints.weighty = 0.9; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); botones.add(panelRelleno, gridBagConstraints); JLabel labelPreguntas = new JLabel("PREGUNTAS"); labelPreguntas.setFont(new Font("Roboto", 1, 24)); labelPreguntas.setHorizontalAlignment(0); labelPreguntas.setForeground(new Color(137, 36, 31)); panelContainer.add(labelPreguntas); for (Pregunta pregunta : votacion.getPreguntas()) { Boton boton = new Boton("<html><div align=center>" + pregunta.getTitulo() + "</html>") { @Override public void botonClicked(Boton e) { crearGrafica(pregunta); botonActual = e; } }; boton.setPreferredSize(new Dimension(200, 0)); panelContainer.add(boton); if (!first) { botonActual = boton; first = true; } } botones.repaint(); botones.revalidate(); }
From source file:components.DialogDemo.java
/** Creates the panel shown by the second tab. */ private JPanel createFeatureDialogBox() { final int numButtons = 5; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); JButton showItButton = null;/* w w w . ja v a 2 s . co m*/ final String pickOneCommand = "pickone"; final String textEnteredCommand = "textfield"; final String nonAutoCommand = "nonautooption"; final String customOptionCommand = "customoption"; final String nonModalCommand = "nonmodal"; radioButtons[0] = new JRadioButton("Pick one of several choices"); radioButtons[0].setActionCommand(pickOneCommand); radioButtons[1] = new JRadioButton("Enter some text"); radioButtons[1].setActionCommand(textEnteredCommand); radioButtons[2] = new JRadioButton("Non-auto-closing dialog"); radioButtons[2].setActionCommand(nonAutoCommand); radioButtons[3] = new JRadioButton("Input-validating dialog " + "(with custom message area)"); radioButtons[3].setActionCommand(customOptionCommand); radioButtons[4] = new JRadioButton("Non-modal dialog"); radioButtons[4].setActionCommand(nonModalCommand); for (int i = 0; i < numButtons; i++) { group.add(radioButtons[i]); } radioButtons[0].setSelected(true); showItButton = new JButton("Show it!"); showItButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); //pick one of many if (command == pickOneCommand) { Object[] possibilities = { "ham", "spam", "yam" }; String s = (String) JOptionPane.showInputDialog(frame, "Complete the sentence:\n" + "\"Green eggs and...\"", "Customized Dialog", JOptionPane.PLAIN_MESSAGE, icon, possibilities, "ham"); //If a string was returned, say so. if ((s != null) && (s.length() > 0)) { setLabel("Green eggs and... " + s + "!"); return; } //If you're here, the return value was null/empty. setLabel("Come on, finish the sentence!"); //text input } else if (command == textEnteredCommand) { String s = (String) JOptionPane.showInputDialog(frame, "Complete the sentence:\n" + "\"Green eggs and...\"", "Customized Dialog", JOptionPane.PLAIN_MESSAGE, icon, null, "ham"); //If a string was returned, say so. if ((s != null) && (s.length() > 0)) { setLabel("Green eggs and... " + s + "!"); return; } //If you're here, the return value was null/empty. setLabel("Come on, finish the sentence!"); //non-auto-closing dialog } else if (command == nonAutoCommand) { final JOptionPane optionPane = new JOptionPane( "The only way to close this dialog is by\n" + "pressing one of the following buttons.\n" + "Do you understand?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); //You can't use pane.createDialog() because that //method sets up the JDialog with a property change //listener that automatically closes the window //when a button is clicked. final JDialog dialog = new JDialog(frame, "Click a button", true); dialog.setContentPane(optionPane); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { setLabel("Thwarted user attempt to close window."); } }); optionPane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if (dialog.isVisible() && (e.getSource() == optionPane) && (JOptionPane.VALUE_PROPERTY.equals(prop))) { //If you were going to check something //before closing the window, you'd do //it here. dialog.setVisible(false); } } }); dialog.pack(); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); int value = ((Integer) optionPane.getValue()).intValue(); if (value == JOptionPane.YES_OPTION) { setLabel("Good."); } else if (value == JOptionPane.NO_OPTION) { setLabel("Try using the window decorations " + "to close the non-auto-closing dialog. " + "You can't!"); } else { setLabel("Window unavoidably closed (ESC?)."); } //non-auto-closing dialog with custom message area //NOTE: if you don't intend to check the input, //then just use showInputDialog instead. } else if (command == customOptionCommand) { customDialog.setLocationRelativeTo(frame); customDialog.setVisible(true); String s = customDialog.getValidatedText(); if (s != null) { //The text is valid. setLabel("Congratulations! " + "You entered \"" + s + "\"."); } //non-modal dialog } else if (command == nonModalCommand) { //Create the dialog. final JDialog dialog = new JDialog(frame, "A Non-Modal Dialog"); //Add contents to it. It must have a close button, //since some L&Fs (notably Java/Metal) don't provide one //in the window decorations for dialogs. JLabel label = new JLabel("<html><p align=center>" + "This is a non-modal dialog.<br>" + "You can have one or more of these up<br>" + "and still use the main window."); label.setHorizontalAlignment(JLabel.CENTER); Font font = label.getFont(); label.setFont(label.getFont().deriveFont(font.PLAIN, 14.0f)); JButton closeButton = new JButton("Close"); closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.setVisible(false); dialog.dispose(); } }); JPanel closePanel = new JPanel(); closePanel.setLayout(new BoxLayout(closePanel, BoxLayout.LINE_AXIS)); closePanel.add(Box.createHorizontalGlue()); closePanel.add(closeButton); closePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 5)); JPanel contentPane = new JPanel(new BorderLayout()); contentPane.add(label, BorderLayout.CENTER); contentPane.add(closePanel, BorderLayout.PAGE_END); contentPane.setOpaque(true); dialog.setContentPane(contentPane); //Show it. dialog.setSize(new Dimension(300, 150)); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); } } }); return createPane(moreDialogDesc + ":", radioButtons, showItButton); }
From source file:edu.harvard.mcz.imagecapture.GeoreferenceDialog.java
private void init() { setBounds(100, 100, 450, 560);// ww w . jav a2s. c o m getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(new GridLayout(0, 2, 0, 0)); { JLabel lblLatitude = new JLabel("Latitude"); lblLatitude.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblLatitude); } textFieldDecimalLat = new JTextField(); contentPanel.add(textFieldDecimalLat); textFieldDecimalLat.setColumns(10); JLabel lblLongitude = new JLabel("Longitude"); lblLongitude.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblLongitude); { textFieldDecimalLong = new JTextField(); contentPanel.add(textFieldDecimalLong); textFieldDecimalLong.setColumns(10); } { JLabel lblDatum = new JLabel("Datum"); lblDatum.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblDatum); } @SuppressWarnings("unchecked") ComboBoxModel<String> datumModel = new ListComboBoxModel<String>(LatLong.getDatumValues()); cbDatum = new JComboBox<String>(datumModel); contentPanel.add(cbDatum); JLabel lblMethod = new JLabel("Method"); lblMethod.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblMethod); @SuppressWarnings("unchecked") ComboBoxModel<String> methodModel = new ListComboBoxModel<String>(LatLong.getGeorefMethodValues()); cbMethod = new JComboBox<String>(new DefaultComboBoxModel<String>(new String[] { "not recorded", "unknown", "GEOLocate", "Google Earth", "Gazeteer", "GPS", "MaNIS/HertNet/ORNIS Georeferencing Guidelines" })); cbMethod.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setState(); } }); contentPanel.add(cbMethod); JLabel lblAccuracy = new JLabel("GPS Accuracy"); lblAccuracy.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblAccuracy); txtGPSAccuracy = new JTextField(); txtGPSAccuracy.setColumns(10); contentPanel.add(txtGPSAccuracy); JLabel lblNewLabel_1 = new JLabel("Original Units"); lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblNewLabel_1); comboBoxOrigUnits = new JComboBox<String>(); comboBoxOrigUnits.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setState(); } }); comboBoxOrigUnits.setModel(new DefaultComboBoxModel<String>( new String[] { "decimal degrees", "deg. min. sec.", "degrees dec. minutes", "unknown" })); contentPanel.add(comboBoxOrigUnits); lblErrorRadius = new JLabel("Error Radius"); lblErrorRadius.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblErrorRadius); txtErrorRadius = new JTextField(); txtErrorRadius.setColumns(10); contentPanel.add(txtErrorRadius); JLabel lblErrorRadiusUnits = new JLabel("Error Radius Units"); lblErrorRadiusUnits.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblErrorRadiusUnits); comboBoxErrorUnits = new JComboBox<String>(); comboBoxErrorUnits.setModel(new DefaultComboBoxModel<String>(new String[] { "m", "ft", "km", "mi", "yd" })); contentPanel.add(comboBoxErrorUnits); JLabel lblLatDegrees = new JLabel("Lat Degrees"); lblLatDegrees.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblLatDegrees); txtLatDegrees = new JTextField(); txtLatDegrees.setColumns(4); contentPanel.add(txtLatDegrees); JLabel lblLatDecMin = new JLabel("Lat Dec Min"); lblLatDecMin.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblLatDecMin); txtLatDecMin = new JTextField(); txtLatDecMin.setColumns(6); contentPanel.add(txtLatDecMin); JLabel lblLatMin = new JLabel("Lat Min"); lblLatMin.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblLatMin); txtLatMin = new JTextField(); txtLatMin.setColumns(6); contentPanel.add(txtLatMin); JLabel lblLatSec = new JLabel("Lat Sec"); lblLatSec.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblLatSec); txtLatSec = new JTextField(); txtLatSec.setColumns(6); contentPanel.add(txtLatSec); JLabel lblLatDir = new JLabel("Lat N/S"); lblLatDir.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblLatDir); cbLatDir = new JComboBox<String>(); cbLatDir.setModel(new DefaultComboBoxModel<String>(new String[] { "N", "S" })); contentPanel.add(cbLatDir); JLabel lblLongDegrees = new JLabel("Long Degrees"); lblLongDegrees.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblLongDegrees); txtLongDegrees = new JTextField(); txtLongDegrees.setColumns(4); contentPanel.add(txtLongDegrees); JLabel lblLongDecMin = new JLabel("Long Dec Min"); lblLongDecMin.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblLongDecMin); txtLongDecMin = new JTextField(); txtLongDecMin.setColumns(6); contentPanel.add(txtLongDecMin); JLabel lblLongMin = new JLabel("Long Min"); lblLongMin.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblLongMin); txtLongMin = new JTextField(); txtLongMin.setColumns(6); contentPanel.add(txtLongMin); JLabel lblLongSec = new JLabel("Long Sec"); lblLongSec.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblLongSec); txtLongSec = new JTextField(); txtLongSec.setColumns(6); contentPanel.add(txtLongSec); JLabel lblLongDir = new JLabel("Long E/W"); lblLongDir.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblLongDir); cbLongDir = new JComboBox<String>(); cbLongDir.setModel(new DefaultComboBoxModel<String>(new String[] { "E", "W" })); contentPanel.add(cbLongDir); JLabel lblDetBy = new JLabel("Determined By"); lblDetBy.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblDetBy); textFieldDetBy = new JTextField(); contentPanel.add(textFieldDetBy); textFieldDetBy.setColumns(10); JLabel lblDetDate = new JLabel("Date Determined"); lblDetDate.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblDetDate); try { textDetDate = new JFormattedTextField(new MaskFormatter("####-##-##")); } catch (ParseException e1) { textDetDate = new JFormattedTextField(); } textDetDate.setToolTipText("Date on which georeference was made yyyy-mm-dd"); contentPanel.add(textDetDate); JLabel lblRef = new JLabel("Reference Source"); lblRef.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblRef); textRefSource = new JTextField(); contentPanel.add(textRefSource); textRefSource.setColumns(10); lblNewLabel = new JLabel("Remarks"); lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT); contentPanel.add(lblNewLabel); textFieldRemarks = new JTextField(); contentPanel.add(textFieldRemarks); textFieldRemarks.setColumns(10); { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { lblErrorLabel = new JLabel("Message"); buttonPane.add(lblErrorLabel); } { okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { lblErrorLabel.setText(""); if (saveData()) { setVisible(false); } } }); okButton.setActionCommand("OK"); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); } { JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { loadData(); setVisible(false); } }); cancelButton.setActionCommand("Cancel"); buttonPane.add(cancelButton); } } }
From source file:com.sec.ose.osi.ui.frm.login.JPanLogin.java
/** * This method initializes jPanelUserInfo * /*from ww w . j a va2 s .c o m*/ * @return javax.swing.JPanel */ private JPanel getJPanelUserInfo() { if (jPanelUserInfo == null) { jPanelUserInfo = new JPanel(); jPanelUserInfo.setLayout(new GridBagLayout()); // User ID JLabel jLabelUser = new JLabel("User ID:"); jLabelUser.setHorizontalAlignment(SwingConstants.RIGHT); jLabelUser.setText("User ID :"); jLabelUser.setEnabled(true); GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridy = 0; gridBagConstraints.gridx = 0; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new Insets(0, 10, 0, 0); jPanelUserInfo.add(jLabelUser, gridBagConstraints); GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); gridBagConstraints1.fill = GridBagConstraints.BOTH; gridBagConstraints1.gridy = 0; gridBagConstraints1.gridx = 1; gridBagConstraints1.weightx = 1.0; gridBagConstraints1.insets = new Insets(5, 5, 5, 5); jPanelUserInfo.add(getJTextFieldUser(), gridBagConstraints1); // Password JLabel jLabelPwd = new JLabel(); jLabelPwd.setText("Password :"); jLabelPwd.setHorizontalAlignment(SwingConstants.RIGHT); GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); gridBagConstraints2.gridy = 1; gridBagConstraints2.gridx = 0; gridBagConstraints2.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints2.insets = new Insets(0, 10, 0, 0); jPanelUserInfo.add(jLabelPwd, gridBagConstraints2); GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); gridBagConstraints3.fill = GridBagConstraints.BOTH; gridBagConstraints3.gridy = 1; gridBagConstraints3.gridx = 1; gridBagConstraints3.weightx = 1.0; gridBagConstraints3.insets = new Insets(5, 5, 5, 5); jPanelUserInfo.add(getJPasswordField(), gridBagConstraints3); // Protex Server IP JLabel jLabelServer = new JLabel(); jLabelServer.setText("Protex Server IP :"); jLabelServer.setHorizontalAlignment(SwingConstants.RIGHT); jLabelServer.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED); GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); gridBagConstraints11.gridy = 2; gridBagConstraints11.gridx = 0; gridBagConstraints11.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints11.insets = new Insets(0, 10, 5, 0); jPanelUserInfo.add(jLabelServer, gridBagConstraints11); GridBagConstraints gridBagConstraints21 = new GridBagConstraints(); gridBagConstraints21.gridy = 2; gridBagConstraints21.gridx = 1; gridBagConstraints21.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints21.insets = new Insets(5, 5, 10, 5); jPanelUserInfo.add(getJTextFieldServerIP(), gridBagConstraints21); } return jPanelUserInfo; }
From source file:com.sec.ose.osi.ui.frm.login.JPanLogin.java
private JPanel getJPanelProxyInfo() { if (jPanelProxyInfo == null) { jPanelProxyInfo = new JPanel(); jPanelProxyInfo.setLayout(new GridBagLayout()); // Proxy Host JLabel jLabelProxyHost = new JLabel("Proxy Host :"); jLabelProxyHost.setHorizontalAlignment(SwingConstants.RIGHT); GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridy = 0;//from ww w .j av a2 s .c om gridBagConstraints.gridx = 0; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new Insets(0, 10, 0, 0); jPanelProxyInfo.add(jLabelProxyHost, gridBagConstraints); GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); gridBagConstraints1.fill = GridBagConstraints.BOTH; gridBagConstraints1.gridy = 0; gridBagConstraints1.gridx = 1; gridBagConstraints1.weightx = 0.5; gridBagConstraints1.insets = new Insets(5, 5, 5, 5); jPanelProxyInfo.add(getJTextProxyHost(), gridBagConstraints1); // Proxy Port JLabel jLabelProxyPort = new JLabel("Port :"); jLabelProxyPort.setHorizontalAlignment(SwingConstants.RIGHT); GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); gridBagConstraints2.gridy = 0; gridBagConstraints2.gridx = 2; gridBagConstraints2.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints2.insets = new Insets(0, 10, 0, 0); jPanelProxyInfo.add(jLabelProxyPort, gridBagConstraints2); GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); gridBagConstraints3.fill = GridBagConstraints.BOTH; gridBagConstraints3.gridy = 0; gridBagConstraints3.gridx = 3; gridBagConstraints3.weightx = 0.5; gridBagConstraints3.insets = new Insets(5, 5, 5, 5); jPanelProxyInfo.add(getJTextProxyPort(), gridBagConstraints3); // Proxy Bypass JLabel jLabelProxyBypass = new JLabel(); jLabelProxyBypass.setText(" Proxy Bypass :"); jLabelProxyBypass.setHorizontalAlignment(SwingConstants.RIGHT); jLabelProxyBypass.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED); GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); gridBagConstraints11.gridy = 1; gridBagConstraints11.gridx = 0; gridBagConstraints11.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints11.insets = new Insets(0, 10, 5, 0); jPanelProxyInfo.add(jLabelProxyBypass, gridBagConstraints11); GridBagConstraints gridBagConstraints21 = new GridBagConstraints(); gridBagConstraints21.gridy = 1; gridBagConstraints21.gridx = 1; gridBagConstraints21.gridwidth = 3; //gridBagConstraints21.weightx = 1.0; gridBagConstraints21.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints21.insets = new Insets(5, 5, 10, 5); jPanelProxyInfo.add(getJTextProxyBypass(), gridBagConstraints21); } return jPanelProxyInfo; }