List of usage examples for javax.swing JDialog setBounds
public void setBounds(int x, int y, int width, int height)
The width or height values are automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize .
From source file:Main.java
public static void main(String[] args) { final JFrame parent = new JFrame("Parent Frame"); parent.setLayout(new FlowLayout()); parent.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); parent.setBounds(100, 100, 300, 200); parent.setVisible(true);/*from ww w . ja v a 2 s.c om*/ JDialog dialog1 = new JDialog(parent, "Dialog1 - Modeless Dialog"); dialog1.setBounds(200, 200, 300, 200); dialog1.setVisible(true); JDialog dialog2 = new JDialog(parent, "Dialog2 - Document-Modal Dialog", Dialog.ModalityType.DOCUMENT_MODAL); dialog2.setBounds(300, 300, 300, 200); JDialog dialog3 = new JDialog(dialog2, "Dialog3 - Modeless Dialog"); dialog3.setBounds(400, 400, 300, 200); dialog3.setVisible(true); dialog2.setVisible(true); }
From source file:ApplicationModalDialogWithExcludeDemo.java
public static void main(String[] args) { final JFrame parent1 = new JFrame("Parent Frame 1"); parent1.setLayout(new FlowLayout()); parent1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); parent1.setBounds(100, 100, 200, 150); parent1.setVisible(true);/* www . ja v a 2 s. c om*/ JFrame parent2 = new JFrame("Parent Frame 2"); parent2.setBounds(500, 100, 300, 150); parent2.setVisible(true); JFrame parent3 = new JFrame("Parent Frame 3 - Excluded"); parent3.setBounds(300, 400, 300, 150); parent3.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); parent3.setVisible(true); JDialog dialog = new JDialog(parent1, "Application-Modal Dialog", Dialog.ModalityType.APPLICATION_MODAL); dialog.setBounds(300, 200, 300, 150); dialog.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JFrame parent1 = new JFrame("Parent Frame 1"); parent1.setLayout(new FlowLayout()); parent1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Application modal dialog"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JDialog dialog = new JDialog(parent1, "Application-Modal Dialog", Dialog.ModalityType.APPLICATION_MODAL); dialog.setBounds(200, 150, 200, 150); dialog.setVisible(true);//from w w w. j a va2 s . c o m } }); parent1.add(button); parent1.setBounds(100, 100, 200, 150); parent1.setVisible(true); JFrame parent2 = new JFrame("Parent Frame 2"); parent2.setBounds(500, 100, 200, 150); parent2.setVisible(true); }
From source file:Main.java
public static void setDialogWindowToCenter(JDialog dialog) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); dialog.setBounds((screenSize.width - dialog.getWidth()) / 2, (screenSize.height - dialog.getHeight()) / 2, dialog.getWidth(), dialog.getHeight()); }
From source file:org.yccheok.jstock.gui.charting.DynamicChart.java
public void showNewJDialog(java.awt.Frame parent, String title) { TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(this.price); JFreeChart freeChart = ChartFactory.createTimeSeriesChart(title, GUIBundle.getString("DynamicChart_Date"), GUIBundle.getString("DynamicChart_Price"), dataset, true, true, false); freeChart.setAntiAlias(true);/*ww w . j a va 2 s. c o m*/ XYPlot plot = freeChart.getXYPlot(); NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis(); DecimalFormat format = new DecimalFormat("00.00"); rangeAxis1.setNumberFormatOverride(format); XYItemRenderer renderer1 = plot.getRenderer(); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("h:mm:ss a"), new DecimalFormat("0.00#"))); org.yccheok.jstock.charting.Utils.applyChartTheme(freeChart); ChartPanel _chartPanel = new ChartPanel(freeChart, true, true, true, true, true); JDialog dialog = new JDialog(parent, title, false); dialog.getContentPane().add(_chartPanel, java.awt.BorderLayout.CENTER); dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); final java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); dialog.setBounds((screenSize.width - 750) >> 1, (screenSize.height - 600) >> 1, 750, 600); dialog.setVisible(true); }
From source file:ui.frame.UILogin.java
public UILogin() { super("Login"); Label l = new Label(); setLayout(new BorderLayout()); this.setPreferredSize(new Dimension(400, 300)); Panel p = new Panel(); loginPanel = p.createPanel(Layouts.grid, 4, 2); loginPanel.setBorder(new EmptyBorder(25, 25, 0, 25)); lblUser = l.createLabel("Username:"); lblPassword = l.createLabel("Password:"); lblURL = l.createLabel("Server URL"); lblBucket = l.createLabel("Bucket"); tfURL = new JTextField(); tfURL.setText("kaiup.kaisquare.com"); tfBucket = new JTextField(); PromptSupport.setPrompt("BucketName", tfBucket); tfUser = new JTextField(); PromptSupport.setPrompt("Username", tfUser); pfPassword = new JPasswordField(); PromptSupport.setPrompt("Password", pfPassword); buttonPanel = p.createPanel(Layouts.flow); buttonPanel.setBorder(new EmptyBorder(0, 0, 25, 0)); Button b = new Button(); JButton btnLogin = b.createButton("Login"); JButton btnExit = b.createButton("Exit"); btnLogin.setPreferredSize(new Dimension(150, 50)); btnExit.setPreferredSize(new Dimension(150, 50)); Component[] arrayBtn = { btnExit, btnLogin }; p.addComponentsToPanel(buttonPanel, arrayBtn); Component[] arrayComponents = { lblURL, tfURL, lblBucket, tfBucket, lblUser, tfUser, lblPassword, pfPassword };/*w ww . ja va2s. c o m*/ p.addComponentsToPanel(loginPanel, arrayComponents); add(loginPanel, BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH); pack(); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); btnLogin.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { if (tfUser.getText().equals("") || String.valueOf(pfPassword.getPassword()).equals("") || tfBucket.getText().equals("")) { JOptionPane.showMessageDialog(Data.mainFrame, "Please fill up all the fields", "Error", JOptionPane.ERROR_MESSAGE); } else { String username = tfUser.getText(); String password = String.valueOf(pfPassword.getPassword()); Data.URL = Data.protocol + tfURL.getText(); Data.targetURL = Data.protocol + tfURL.getText() + "/api/" + tfBucket.getText() + "/"; String response = api.loginBucket(Data.targetURL, username, password); try { if (DesktopAppMain.checkResult(response)) { JSONObject responseJSON = new JSONObject(response); Data.sessionKey = responseJSON.get("session-key").toString(); response = api.getUserFeatures(Data.targetURL, Data.sessionKey); if (checkFeatures(response)) { Data.mainFrame = new KAIQRFrame(); Data.mainFrame.uiInventorySelect = new UIInventorySelect(); Data.mainFrame.addPanel(Data.mainFrame.uiInventorySelect, "inventory"); Data.mainFrame.showPanel("inventory"); Data.mainFrame.pack(); setVisible(false); Data.mainFrame.setVisible(true); } else { JOptionPane.showMessageDialog(Data.loginFrame, "User does not have necessary features", "Error", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(Data.loginFrame, "Wrong username/password", "Error", JOptionPane.ERROR_MESSAGE); } } catch (JSONException e1) { e1.printStackTrace(); } } return null; } }; Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource()); final JDialog dialog = new JDialog(win, "Login", ModalityType.APPLICATION_MODAL); mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("state")) { if (evt.getNewValue() == SwingWorker.StateValue.DONE) { dialog.dispose(); } } } }); mySwingWorker.execute(); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Logging in .........."), BorderLayout.PAGE_START); dialog.add(panel); dialog.pack(); dialog.setBounds(50, 50, 300, 100); dialog.setLocationRelativeTo(Data.mainFrame); dialog.setVisible(true); } }); btnExit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); }
From source file:ui.panel.UIAccessKeySelect.java
public void runaccessKeySelect() { getAccessKeyData();/*from w w w. j ava 2 s. c o m*/ Panel p = new Panel(); Button b = new Button(); Label l = new Label(); setLayout(new BorderLayout()); JPanel pnlInstruction = p.createPanel(Layouts.flow); JLabel lblInstruction = l.createLabel("Access Keys"); pnlInstruction.setBackground(CustomColor.LightBlue.returnColor()); lblInstruction.setForeground(Color.white); lblInstruction.setFont(new Font("San Serif", Font.PLAIN, 18)); pnlInstruction.add(lblInstruction); JPanel pnlBucketList = p.createPanel(Layouts.border); listBucket.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scrollBucket = new JScrollPane(listBucket); Component[] BucketListComponents = { scrollBucket }; pnlBucketList.add(scrollBucket, BorderLayout.CENTER); JPanel pnlButtons = p.createPanel(Layouts.flow); JButton btnBack = b.createButton("Back"); JButton btnSelectElements = b.createButton("Next"); JButton btnAdd = b.createButton("Generate Access Key"); JButton btnRefresh = b.createButton("Refresh"); pnlButtons.add(btnBack); pnlButtons.add(btnAdd); pnlButtons.add(btnRefresh); pnlButtons.add(btnSelectElements); add(pnlInstruction, BorderLayout.NORTH); add(pnlBucketList, BorderLayout.CENTER); add(pnlButtons, BorderLayout.SOUTH); btnBack.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Data.mainFrame.showPanel("license"); } }); btnRefresh.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { getAccessKeyData(); } }); btnAdd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Data.mainFrame.uiGenerateKey = new UIGenerateKey(); Data.mainFrame.addPanel(Data.mainFrame.uiGenerateKey, "generateKey"); Data.mainFrame.pack(); Data.mainFrame.showPanel("generateKey"); } }); btnSelectElements.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { int selected = listBucket.getSelectedRow(); if (selected != -1) { Data.accessKey = (String) listBucket.getModel().getValueAt(selected, 0); Data.mainFrame.qrGenerator = new JavaQR(); Data.mainFrame.pack(); Data.mainFrame.addPanel(Data.mainFrame.qrGenerator, "generateQR"); Data.mainFrame.showPanel("generateQR"); } else { JOptionPane.showMessageDialog(Data.mainFrame, "Please Select Access Key", "Error", JOptionPane.ERROR_MESSAGE); } return null; } }; Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource()); final JDialog dialog = new JDialog(win, "Loading", ModalityType.APPLICATION_MODAL); mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("state")) { if (evt.getNewValue() == SwingWorker.StateValue.DONE) { dialog.dispose(); } } } }); mySwingWorker.execute(); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Generating QR Code......."), BorderLayout.PAGE_START); dialog.add(panel); dialog.pack(); dialog.setBounds(50, 50, 300, 100); dialog.setLocationRelativeTo(Data.mainFrame); dialog.setVisible(true); } }); }
From source file:ui.panel.UIBucketSelect.java
public void runBucketSelect() { Panel p = new Panel(); Button b = new Button(); Label l = new Label(); setLayout(new BorderLayout()); JPanel pnlInstruction = p.createPanel(Layouts.flow); JLabel lblInstruction = l.createLabel("Bucket List"); pnlInstruction.setBackground(CustomColor.LightBlue.returnColor()); lblInstruction.setForeground(Color.white); lblInstruction.setFont(new Font("San Serif", Font.PLAIN, 18)); pnlInstruction.add(lblInstruction);//from w w w.ja v a 2 s.co m JPanel pnlBucketList = p.createPanel(Layouts.border); listBucket.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scrollBucket = new JScrollPane(listBucket); scrollBucket.setPreferredSize(new Dimension(300, 150)); pnlBucketList.add(scrollBucket, BorderLayout.CENTER); JPanel pnlButtons = p.createPanel(Layouts.flow); JButton btnBack = b.createButton("Back"); JButton btnSelectElements = b.createButton("Next"); JButton btnRefresh = b.createButton("Refresh Bucket List"); pnlButtons.add(btnBack); pnlButtons.add(btnRefresh); pnlButtons.add(btnSelectElements); add(pnlInstruction, BorderLayout.NORTH); add(pnlBucketList, BorderLayout.CENTER); add(pnlButtons, BorderLayout.SOUTH); setVisible(true); btnRefresh.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { getBucketData(); } }); btnSelectElements.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { int selected = listBucket.getSelectedRow(); if (selected == -1) { JOptionPane.showMessageDialog(Data.mainFrame, "Please Select a Bucket", "Error", JOptionPane.ERROR_MESSAGE); } else { Data.bucketID = (int) listBucket.getModel().getValueAt(selected, 0); Data.mainFrame.addPanel(Data.mainFrame.uiLicenseDetail = new UILicenseDetail(), "license"); Data.mainFrame.pack(); Data.mainFrame.showPanel("license"); } return null; } }; Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource()); final JDialog dialog = new JDialog(win, "Loading", ModalityType.APPLICATION_MODAL); mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("state")) { if (evt.getNewValue() == SwingWorker.StateValue.DONE) { dialog.dispose(); } } } }); mySwingWorker.execute(); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Retrieving Licenses......."), BorderLayout.PAGE_START); dialog.add(panel); dialog.pack(); dialog.setBounds(50, 50, 300, 100); dialog.setLocationRelativeTo(Data.mainFrame); dialog.setVisible(true); } }); btnBack.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); Data.mainFrame.showPanel("inventory"); } }); }
From source file:ui.panel.UILicenseAdd.java
public JPanel createButtonPanel() { JPanel panel = p.createPanel(Layouts.flow); panel.setLayout(new FlowLayout(FlowLayout.CENTER)); btnSubmit = b.createButton("Submit"); btnCancel = b.createButton("Cancel"); btnSubmit.addActionListener(new ActionListener() { @Override// w ww .ja va 2 s .c om public void actionPerformed(ActionEvent e) { SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { TreePath[] path = checkTreeManager.getSelectionModel().getSelectionPaths(); ArrayList<String> featureL = new ArrayList<String>(); String[] features = new String[] {}; for (TreePath tp : path) { if (tp.getLastPathComponent().toString().equals("Features")) { Object rootNode = tree.getModel().getRoot(); int parentCount = tree.getModel().getChildCount(rootNode); for (int i = 0; i < parentCount; i++) { Object parentNode = tree.getModel().getChild(rootNode, i); int childrenCount = tree.getModel().getChildCount(parentNode); for (int x = 0; x < childrenCount; x++) { MyDataNode node = (MyDataNode) tree.getModel().getChild(parentNode, x); featureL.add(node.getValue()); } } } else if (tp.getPathCount() == 2) { Object rootNode = tree.getModel().getRoot(); int parentCount = tree.getModel().getChildCount(rootNode); for (int i = 0; i < parentCount; i++) { Object parentNode = tree.getModel().getChild(rootNode, i); if (parentNode.toString().equals(tp.getLastPathComponent().toString())) { int childrenCount = tree.getModel().getChildCount(parentNode); for (int x = 0; x < childrenCount; x++) { MyDataNode node = (MyDataNode) tree.getModel().getChild(parentNode, x); featureL.add(node.getValue()); } } } } else if (tp.getPathCount() == 3) { MyDataNode node = (MyDataNode) tp.getLastPathComponent(); featureL.add(node.getValue()); } } features = featureL.toArray(features); String duration = spnValidity.getValue().toString(); if (cbPerpetual.isSelected()) { duration = "-1"; } String storage = spnCloud.getValue().toString(); String maxVCA = spnConcurrentVCA.getValue().toString(); String response = apiCall.addNodeLicense(Data.targetURL, Data.sessionKey, Data.bucketID, features, duration, storage, maxVCA); try { JSONObject responseObject = new JSONObject(response); if (responseObject.get("result").equals("ok")) { Data.mainFrame.uiLicenseDetail.getLicenseData(); Data.mainFrame.showPanel("license"); } } catch (JSONException e1) { e1.printStackTrace(); } return null; } }; Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource()); final JDialog dialog = new JDialog(win, "Loading", ModalityType.APPLICATION_MODAL); mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("state")) { if (evt.getNewValue() == SwingWorker.StateValue.DONE) { dialog.dispose(); } } } }); mySwingWorker.execute(); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Retrieving License..."), BorderLayout.PAGE_START); dialog.add(panel); dialog.pack(); dialog.setBounds(50, 50, 300, 100); dialog.setLocationRelativeTo(Data.mainFrame); dialog.setVisible(true); } }); btnCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); Data.mainFrame.showPanel("license"); } }); panel.add(btnSubmit); panel.add(btnCancel); return panel; }
From source file:ui.panel.UILicenseDetail.java
public JPanel createButtonPanel() { JPanel panel = p.createPanel(Layouts.flow); panel.setLayout(new FlowLayout(FlowLayout.CENTER)); btnSubmit = b.createButton("Next"); btnBack = b.createButton("Back"); btnAdd = b.createButton("Add License"); panel.add(btnBack);/* ww w. jav a2 s . co m*/ panel.add(btnAdd); panel.add(btnSubmit); btnBack.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Data.mainFrame.showPanel("bucket"); } }); btnAdd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Data.mainFrame.addPanel(Data.mainFrame.uiLicenseAdd = new UILicenseAdd(), "licenseAdd"); Data.mainFrame.showPanel("licenseAdd"); } }); btnSubmit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { int row = tblInfo.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(Data.mainFrame, "Please Select a License", "Error", JOptionPane.ERROR_MESSAGE); } else { Data.licenseNumber = (String) tblInfo.getModel().getValueAt(row, 0); Data.mainFrame.uiAccessKeySelect = new UIAccessKeySelect(); Data.mainFrame.addPanel(Data.mainFrame.uiAccessKeySelect, "access"); Data.mainFrame.showPanel("access"); } return null; } }; Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource()); final JDialog dialog = new JDialog(win, "Loading", ModalityType.APPLICATION_MODAL); mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("state")) { if (evt.getNewValue() == SwingWorker.StateValue.DONE) { dialog.dispose(); } } } }); mySwingWorker.execute(); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Retrieving Access Keys"), BorderLayout.PAGE_START); dialog.add(panel); dialog.pack(); dialog.setBounds(50, 50, 300, 100); dialog.setLocationRelativeTo(Data.mainFrame); dialog.setVisible(true); } }); btnBack.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); Data.mainFrame.showPanel("bucket"); } }); btnAdd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); Data.mainFrame.addPanel(Data.mainFrame.uiLicenseAdd = new UILicenseAdd(), "licenseAdd"); Data.mainFrame.pack(); Data.mainFrame.showPanel("licenseAdd"); } }); return panel; }