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 3 of 3

Thread: Setting Location of JColorChooser

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

    Default Setting Location of JColorChooser

    I have a working JColorChooser dialog except it is not located where I want it. I cannot figure out how to set the location without getting a static call warning from my IDE (Eclipse). This seems like it should be a simple thing to do but I've learned that few things in java are simple. This is the code in question:
    import java.awt.Color;
     
    import javax.swing.JColorChooser;
     
    public class ColorChooser {
     
    	public Color getColor() {
    		JColorChooser chooser=new JColorChooser();
    		chooser.setLocation(0, 0);
    		Color color=chooser.showDialog(null,"Choose color",Color.RED);
    		return(color);
    	}
    }
    The statement 'Color color=...' gets the warning that it needs to be called in a static way. How do I call 'setlocation' and still call 'showDialog in a static way? TIA.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Setting Location of JColorChooser

    static methods should be called using the classname not a reference to an instance of the class.
    Pass this to Google: call static method java for lots of discussions and examples

    JColorChooser dialog except it is not located where I want it
    I don't know of a way to position the dialog window used by showDialog. There might be a way if you create your own dialog window, instead of using showDialog. See the demo examples linked to from the API doc for JColorChooser.
    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: Setting Location of JColorChooser

    Like I said, little in java is simple. I'll take a look. Thanks.

Similar Threads

  1. Specifying the file location
    By fahman_khan75@yahoo.com in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 12th, 2014, 08:36 AM
  2. JColorChooser won't change text color of JLabel
    By mwardjava92 in forum AWT / Java Swing
    Replies: 1
    Last Post: April 4th, 2013, 06:37 PM
  3. [SOLVED] JColorChooser
    By thatguy in forum What's Wrong With My Code?
    Replies: 8
    Last Post: February 26th, 2013, 06:27 PM
  4. Returning location instead of value?
    By cpguy in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 29th, 2011, 04:39 PM
  5. setting location of a dialog relative to the parent
    By dewboy3d in forum AWT / Java Swing
    Replies: 1
    Last Post: August 1st, 2009, 05:42 PM

Tags for this Thread