Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Force JDialog to Upper Right of Screen

  1. #1
    Junior Member
    Join Date
    Apr 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Force JDialog to Upper Right of Screen

    I think I need some new eyes to look at my code. Something I inadvertently changed is causing my JDialog to be centered on the screen rather than opening in the default location (upper left). Can someone spot what I am missing that is causing this? TIA.
    	private static void initialize() {
    		Functions.logger("Initializing probe configuration",false);
    		probeDialog=new JDialog();
    		probeDialog.setLayout(new GridBagLayout());
    		probeDialog.setModalityType(ModalityType.MODELESS);
    		probeDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    		int row=0;
    		JLabel headerLabel=new JLabel("Verify Blower & Probe Configuration");
    		Font headerFont=headerLabel.getFont();
    		headerFont=headerFont.deriveFont(Font.BOLD,(float) 20);
    		headerLabel.setFont(headerFont);
    		GridBagConstraints gbc=new GridBagConstraints();
    		gbc.gridwidth=2;
    		gbc.gridx=1;
    		gbc.gridy=row++;
    		gbc.fill=GridBagConstraints.HORIZONTAL;
    		JLabel nameLabel=new JLabel("Name");
    		JLabel idLabel=new JLabel("ID");
    		JLabel nameLabelB=new JLabel("Name");
    		JLabel idLabelB=new JLabel("ID");
    		JLabel blowerLabel=new JLabel("Blower");
    		JLabel blowersTitle=new JLabel("Blowers");
    		Font titleFont=blowersTitle.getFont().deriveFont(Font.BOLD, (float) 16);
    		blowersTitle.setFont(titleFont);
    		JLabel probesTitle=new JLabel("Probes");
    		probesTitle.setFont(titleFont);
    		JLabel adjustTitle=new JLabel("Adjustment (+/- \u00B0)");
    		probeDialog.add(headerLabel,gbc);
    		probeDialog.add(blowersTitle,Functions.makeGbc(2,row++));
    		probeDialog.add(nameLabelB,Functions.makeGbc(0,row));
    		probeDialog.add(idLabelB,Functions.makeGbc(1,row++));
    		String[] blowers=Configuration.getInstance().getBlowerIds();
    		Functions.logger("Blower ids "+Arrays.toString(blowers),true);
    		for (int i=0; i<blowers.length; i++) {
    			JTextField nme=new JTextField();
    			String name=blowers[i];
    			name=Configuration.getInstance().getBlower(blowers[i]).getName();
    			fields.put(nme,new String[] {"name",name});
    			nme.setText(name);
    			blwrs.put(blowers[i],name);
    			JLabel id=new JLabel();
    			id.setText(blowers[i]);
    			probeDialog.add(nme,Functions.makeGbc(0,row));
    			probeDialog.add(id,Functions.makeGbc(1,row++));
    		}
    		probeDialog.add(probesTitle,Functions.makeGbc(2,row++));
    		probeDialog.add(nameLabel,Functions.makeGbc(0,row));
    		probeDialog.add(idLabel,Functions.makeGbc(1,row));
    		probeDialog.add(blowerLabel,Functions.makeGbc(2,row));
    		probeDialog.add(adjustTitle,Functions.makeGbc(3,row++));
    		String[] monitors=Configuration.getInstance().getMonitorIds();
    		Functions.logger("Monitor ids "+Arrays.toString(monitors),true);
    		for (int i=0; i<monitors.length; i++) {;
    			String name=Configuration.getInstance().getMonitor(monitors[i]).getName();
    			String probeId=Configuration.getInstance().getMonitor(monitors[i]).getId();
    			if (name.equals("")) {
    				Functions.logger("Skipping unconnected probe "+probeId,false);
    				continue;
    			}
    			JTextField nme=new JTextField();
    			fields.put(nme,new String[] {"name",name});
    			nme.setText(name);
    			JLabel id=new JLabel();
    			id.setText(monitors[i]);
    			probeDialog.add(nme,Functions.makeGbc(0,row));
    			probeDialog.add(id,Functions.makeGbc(1,row));
    			JComboBox<String> list=new JComboBox<String>();
    			fields.put(list,new String[] {"combo",name});
    			list.addItem("");
    			for (Object entry : blwrs.values()) {
    				list.addItem((String) entry);
    			}
    			probeDialog.add(list,Functions.makeGbc(2,row));
    			if (!Configuration.getInstance().getMonitor(monitors[i]).getBlowerName().equals("")) {
    				list.setSelectedItem(Configuration.getInstance().getMonitor(monitors[i]).getBlowerName());
    			}
    			JFormattedTextField adjust=new JFormattedTextField(new DecimalFormat("#.00"));
    			if (Configuration.getInstance().getMonitor(monitors[i])!=null) {
    				adjust.setText(Double.toString(Configuration.getInstance().getAdjustment(Configuration.getInstance().getMonitor(monitors[i]).getId())));
    			}
    			else {
    				adjust.setText("0.");
    			}
    			fields.put(adjust,new String[] {"adjust",monitors[i]});
    			probeDialog.add(adjust,Functions.makeGbc(3, row));
    			colorButton=new JButton("Color");
    			colorButton.setForeground(Configuration.getInstance().getColor(probeId));
    			colorButton.addActionListener(new ColorListener(Configuration.getInstance().getMonitor(monitors[i])));			
    			probeDialog.add(colorButton,Functions.makeGbc(4, row++));
    		}
    		JRadioButton stoker1=new JRadioButton("Stoker I");
    		stoker2=new JRadioButton("Stoker II");
    		ButtonGroup grp=new ButtonGroup();
    		grp.add(stoker1);
    		grp.add(stoker2);
    		stoker1.setSelected(!Configuration.getInstance().stokerII);
    		stoker2.setSelected(Configuration.getInstance().stokerII);
    		probeDialog.add(stoker1,Functions.makeGbc(1, row));
    		probeDialog.add(stoker2,Functions.makeGbc(2, row++));
    		JButton saveBtn = new JButton("OK");
    		saveBtn.addActionListener(new SaveButtonListener());
    		probeDialog.add(saveBtn,Functions.makeGbc(2, row));
    		probeDialog.pack();
    		probeDialog.setVisible(true);
    		Functions.logger("Probe configuration complete",false);
    	}

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,407
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: Force JDialog to Upper Right of Screen

    Can you make a small, complete program for testing that compiles, executes and shows the problem?

    Remove all the external dependencies. Just the minimum that is needed to show the problem.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Force JDialog to Upper Right of Screen

    Thanks but I cannot reproduce the problem that way. It is specific to this code. There must be something in it that is causing this. As I said, it was working so I must have inadvertently changed something and I am probably seeing what I expect rather than what is there.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,407
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: Force JDialog to Upper Right of Screen

    Sorry, I need a program that compiles and executes for testing. Remove the dependencies one by one and test to see if the removed code was causing the problem.

    it was working
    Do you have a backup that still works as desired?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Force JDialog to Upper Right of Screen

    Thanks. Yeah, I guess I'll need to do a diff on the 2 versions.

Similar Threads

  1. Replies: 5
    Last Post: October 10th, 2014, 02:24 PM
  2. [SOLVED] Opening JDialog from JDialog
    By Dule in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 6th, 2014, 11:26 AM
  3. [SOLVED] Adjust screen size and button arrangement for any computer screen
    By Prathiksha in forum AWT / Java Swing
    Replies: 4
    Last Post: April 23rd, 2014, 11:11 AM
  4. How to set JFrame and JDialog to appear centered on the screen
    By Steven1983 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 7th, 2014, 08:28 AM
  5. Replies: 9
    Last Post: December 31st, 2011, 01:22 AM