java.awt.Choice Java Examples

The following examples show how to use java.awt.Choice. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChoiceTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void UI() {
    Frame frame = new Frame("Test frame");
    Choice choice = new Choice();

    Stream.of(new String[]{"item 1", "item 2", "item 3"}).forEach(choice::add);
    frame.add(choice);
    frame.setBounds(100, 100, 400, 200);

    frame.setVisible(true);
    Font font = choice.getFont();
    int size = font.getSize();
    int height = choice.getBounds().height;
    try {
        if (height < size) {
            throw new RuntimeException("Test failed");
        }
    } finally {
        frame.dispose();
    }
}
 
Example #2
Source File: ChoicePopupLocation.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void test(final Point tmp) throws Exception {
    Choice choice = new Choice();
    for (int i = 1; i < 7; i++) {
        choice.add("Long-long-long-long-long text in the item-" + i);
    }
    Frame frame = new Frame();
    try {
        frame.setAlwaysOnTop(true);
        frame.setLayout(new FlowLayout());
        frame.add(choice);
        frame.pack();
        frameWidth = frame.getWidth();
        frame.setSize(frameWidth, SIZE);
        frame.setVisible(true);
        frame.setLocation(tmp.x, tmp.y);
        openPopup(choice);
    } finally {
        frame.dispose();
    }
}
 
Example #3
Source File: DrawTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
    this.target = target;
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    target.setForeground(Color.red);
    CheckboxGroup group = new CheckboxGroup();
    Checkbox b;
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.red);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.green);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.blue);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.pink);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.orange);
    add(b = new Checkbox(null, group, true));
    b.addItemListener(this);
    b.setForeground(Color.black);
    target.setForeground(b.getForeground());
    Choice shapes = new Choice();
    shapes.addItemListener(this);
    shapes.addItem("Lines");
    shapes.addItem("Points");
    shapes.setBackground(Color.lightGray);
    add(shapes);
}
 
Example #4
Source File: PreDefinedBoundingBox.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
protected void addListeners(
		final GenericDialog gd,
		final Choice choice,
		final Label label1,
		final Label label2 )
{
	choice.addItemListener( new ItemListener()
	{
		@Override
		public void itemStateChanged(ItemEvent e)
		{
			update( spimData, choice, label1, label2 );
		}
	});

	update( spimData, choice, label1, label2 );
}
 
Example #5
Source File: ChoiceOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean checkComponent(Component comp) {
    if (comp instanceof Choice) {
        if (((Choice) comp).getSelectedItem() != null) {
            return (comparator.equals(((Choice) comp).getSelectedItem(),
                    label));
        }
    }
    return false;
}
 
Example #6
Source File: ChoiceOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code Choice.remove(int)} through queue
 */
public void remove(final int position) {
    runMapping(new MapVoidAction("remove") {
        @Override
        public void map() {
            ((Choice) getSource()).remove(position);
        }
    });
}
 
Example #7
Source File: DrawTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void itemStateChanged(ItemEvent e) {
    if (e.getSource() instanceof Checkbox) {
        target.setForeground(((Component) e.getSource()).getForeground());
    } else if (e.getSource() instanceof Choice) {
        String choice = (String) e.getItem();
        if (choice.equals("Lines")) {
            target.setDrawMode(DrawPanel.LINES);
        } else if (choice.equals("Points")) {
            target.setDrawMode(DrawPanel.POINTS);
        }
    }
}
 
Example #8
Source File: ChoiceOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code Choice.select(int)} through queue
 */
public void select(final int pos) {
    runMapping(new MapVoidAction("select") {
        @Override
        public void map() {
            ((Choice) getSource()).select(pos);
        }
    });
}
 
Example #9
Source File: DrawTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void itemStateChanged(ItemEvent e) {
    if (e.getSource() instanceof Checkbox) {
        target.setForeground(((Component) e.getSource()).getForeground());
    } else if (e.getSource() instanceof Choice) {
        String choice = (String) e.getItem();
        if (choice.equals("Lines")) {
            target.setDrawMode(DrawPanel.LINES);
        } else if (choice.equals("Points")) {
            target.setDrawMode(DrawPanel.POINTS);
        }
    }
}
 
Example #10
Source File: ChoiceOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code Choice.removeAll()} through queue
 */
public void removeAll() {
    runMapping(new MapVoidAction("removeAll") {
        @Override
        public void map() {
            ((Choice) getSource()).removeAll();
        }
    });
}
 
Example #11
Source File: ChoiceOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code Choice.getSelectedItem()} through queue
 */
public String getSelectedItem() {
    return (runMapping(new MapAction<String>("getSelectedItem") {
        @Override
        public String map() {
            return ((Choice) getSource()).getSelectedItem();
        }
    }));
}
 
Example #12
Source File: Stitching_2D.java    From Stitching with GNU General Public License v2.0 5 votes vote down vote up
private final void setRGB(final int imagejID, final Choice target)
{
	if (WindowManager.getImage(imagejID).getType() == ImagePlus.COLOR_RGB || WindowManager.getImage(imagejID).getType() == ImagePlus.COLOR_256)
		target.setEnabled(true);
	else		
		target.setEnabled(false);
}
 
Example #13
Source File: ChoiceOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code Choice.getItemCount()} through queue
 */
public int getItemCount() {
    return (runMapping(new MapIntegerAction("getItemCount") {
        @Override
        public int map() {
            return ((Choice) getSource()).getItemCount();
        }
    }));
}
 
Example #14
Source File: ChoiceOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code Choice.getSelectedIndex()} through queue
 */
public int getSelectedIndex() {
    return (runMapping(new MapIntegerAction("getSelectedIndex") {
        @Override
        public int map() {
            return ((Choice) getSource()).getSelectedIndex();
        }
    }));
}
 
Example #15
Source File: ChoiceOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code Choice.addItemListener(ItemListener)} through queue
 */
public void addItemListener(final ItemListener itemListener) {
    runMapping(new MapVoidAction("addItemListener") {
        @Override
        public void map() {
            ((Choice) getSource()).addItemListener(itemListener);
        }
    });
}
 
Example #16
Source File: BasicTreeConsenser.java    From MesquiteCore with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean queryOptions() {
	MesquiteInteger buttonPressed = new MesquiteInteger(1);
	ExtensibleDialog dialog = new ExtensibleDialog(containerOfModule(), getName() + " Options",buttonPressed);  //MesquiteTrunk.mesquiteTrunk.containerOfModule()
	dialog.addLabel(getName() + " Options");
	String helpString = "Please choose the options for consensus trees. ";

	dialog.appendToHelpString(helpString);

	queryOptionsSetup(dialog);

	
	String[] rootingStrings = {"As specified in first tree", "Rooted", "Unrooted"};
	Choice rootingChoice  = dialog.addPopUpMenu("Treat trees as rooted or unrooted:", rootingStrings, 0);


	//TextArea PAUPOptionsField = queryFilesDialog.addTextArea(PAUPOptions, 20);

	dialog.completeAndShowDialog(true);
	if (buttonPressed.getValue()==0)  {
		queryOptionsProcess(dialog);
		int choiceValue = rootingChoice.getSelectedIndex();
		if (choiceValue>=0)
			rooting = choiceValue;
		storePreferences();

	}
	dialog.dispose();
	return (buttonPressed.getValue()==0);
}
 
Example #17
Source File: ChoiceOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code Choice.getItem(int)} through queue
 */
public String getItem(final int index) {
    return (runMapping(new MapAction<String>("getItem") {
        @Override
        public String map() {
            return ((Choice) getSource()).getItem(index);
        }
    }));
}
 
Example #18
Source File: DitherTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public DitherControls(DitherTest app, int s, int e, DitherMethod type,
        boolean vertical) {
    applet = app;
    setLayout(dcLayout);
    add(new Label(vertical ? "Vertical" : "Horizontal"));
    add(choice = new Choice());
    for (DitherMethod m : DitherMethod.values()) {
        choice.addItem(m.toString().substring(0, 1)
                + m.toString().substring(1).toLowerCase());
    }
    choice.select(type.ordinal());
    add(start = new CardinalTextField(Integer.toString(s), 4));
    add(end = new CardinalTextField(Integer.toString(e), 4));
}
 
Example #19
Source File: ProcessDataFilesLib.java    From MesquiteCore with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected String getImporterName(){
	MesquiteInteger buttonPressed = new MesquiteInteger(1);
	ExtensibleDialog dialog =  new ExtensibleDialog(containerOfModule(), "File Format", buttonPressed);
	String message = "Choose the format of the data files to be processed";
	dialog.addLargeTextLabel(message);
	dialog.addBlankLine();
	dialog.suppressNewPanel();

	MesquiteModule[] fInterpreters = getFileCoordinator().getImmediateEmployeesWithDuty(FileInterpreterI.class);
	int count=1;
	for (int i=0; i<fInterpreters.length; i++) {
		if (((FileInterpreterI)fInterpreters[i]).canImport())
			count++;
	}
	String [] exporterNames = new String[count];
	exporterNames[0] = "NEXUS file";
	count = 1;
	int rememberedNumber = 0;
	for (int i=0; i<fInterpreters.length; i++)
		if (((FileInterpreterI)fInterpreters[i]).canImport()) {
			exporterNames[count] = fInterpreters[i].getName();
			if (exporterNames[count].equalsIgnoreCase(importerString))
				rememberedNumber = count;
			count++;
		}
	Choice exporterChoice = dialog.addPopUpMenu ("File Format", exporterNames, rememberedNumber);
	dialog.addBlankLine();
	dialog.completeAndShowDialog();
	importerString = exporterChoice.getSelectedItem();
	dialog.dispose();
	dialog = null;
	storePreferences();
	return importerString;

}
 
Example #20
Source File: ChoiceOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code Choice.add(String)} through queue
 */
public void add(final String item) {
    runMapping(new MapVoidAction("add") {
        @Override
        public void map() {
            ((Choice) getSource()).add(item);
        }
    });
}
 
Example #21
Source File: ChoiceOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns information about component.
 */
@Override
public Hashtable<String, Object> getDump() {
    Hashtable<String, Object> result = super.getDump();
    if (((Choice) getSource()).getSelectedItem() != null) {
        result.put(SELECTED_ITEM_DPROP, ((Choice) getSource()).getSelectedItem());
    }
    String[] items = new String[((Choice) getSource()).getItemCount()];
    for (int i = 0; i < ((Choice) getSource()).getItemCount(); i++) {
        items[i] = ((Choice) getSource()).getItem(i);
    }
    addToDump(result, ITEM_PREFIX_DPROP, items);
    return result;
}
 
Example #22
Source File: DrawTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
    this.target = target;
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    target.setForeground(Color.red);
    CheckboxGroup group = new CheckboxGroup();
    Checkbox b;
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.red);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.green);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.blue);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.pink);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.orange);
    add(b = new Checkbox(null, group, true));
    b.addItemListener(this);
    b.setForeground(Color.black);
    target.setForeground(b.getForeground());
    Choice shapes = new Choice();
    shapes.addItemListener(this);
    shapes.addItem("Lines");
    shapes.addItem("Points");
    shapes.setBackground(Color.lightGray);
    add(shapes);
}
 
Example #23
Source File: DrawTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void itemStateChanged(ItemEvent e) {
    if (e.getSource() instanceof Checkbox) {
        target.setForeground(((Component) e.getSource()).getForeground());
    } else if (e.getSource() instanceof Choice) {
        String choice = (String) e.getItem();
        if (choice.equals("Lines")) {
            target.setDrawMode(DrawPanel.LINES);
        } else if (choice.equals("Points")) {
            target.setDrawMode(DrawPanel.POINTS);
        }
    }
}
 
Example #24
Source File: DitherTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public DitherControls(DitherTest app, int s, int e, DitherMethod type,
        boolean vertical) {
    applet = app;
    setLayout(dcLayout);
    add(new Label(vertical ? "Vertical" : "Horizontal"));
    add(choice = new Choice());
    for (DitherMethod m : DitherMethod.values()) {
        choice.addItem(m.toString().substring(0, 1)
                + m.toString().substring(1).toLowerCase());
    }
    choice.select(type.ordinal());
    add(start = new CardinalTextField(Integer.toString(s), 4));
    add(end = new CardinalTextField(Integer.toString(e), 4));
}
 
Example #25
Source File: DrawTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
    this.target = target;
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    target.setForeground(Color.red);
    CheckboxGroup group = new CheckboxGroup();
    Checkbox b;
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.red);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.green);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.blue);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.pink);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.orange);
    add(b = new Checkbox(null, group, true));
    b.addItemListener(this);
    b.setForeground(Color.black);
    target.setForeground(b.getForeground());
    Choice shapes = new Choice();
    shapes.addItemListener(this);
    shapes.addItem("Lines");
    shapes.addItem("Points");
    shapes.setBackground(Color.lightGray);
    add(shapes);
}
 
Example #26
Source File: DrawTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
    this.target = target;
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    target.setForeground(Color.red);
    CheckboxGroup group = new CheckboxGroup();
    Checkbox b;
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.red);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.green);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.blue);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.pink);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.orange);
    add(b = new Checkbox(null, group, true));
    b.addItemListener(this);
    b.setForeground(Color.black);
    target.setForeground(b.getForeground());
    Choice shapes = new Choice();
    shapes.addItemListener(this);
    shapes.addItem("Lines");
    shapes.addItem("Points");
    shapes.setBackground(Color.lightGray);
    add(shapes);
}
 
Example #27
Source File: DrawTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void itemStateChanged(ItemEvent e) {
    if (e.getSource() instanceof Checkbox) {
        target.setForeground(((Component) e.getSource()).getForeground());
    } else if (e.getSource() instanceof Choice) {
        String choice = (String) e.getItem();
        if (choice.equals("Lines")) {
            target.setDrawMode(DrawPanel.LINES);
        } else if (choice.equals("Points")) {
            target.setDrawMode(DrawPanel.POINTS);
        }
    }
}
 
Example #28
Source File: DitherTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public DitherControls(DitherTest app, int s, int e, DitherMethod type,
        boolean vertical) {
    applet = app;
    setLayout(dcLayout);
    add(new Label(vertical ? "Vertical" : "Horizontal"));
    add(choice = new Choice());
    for (DitherMethod m : DitherMethod.values()) {
        choice.addItem(m.toString().substring(0, 1)
                + m.toString().substring(1).toLowerCase());
    }
    choice.select(type.ordinal());
    add(start = new CardinalTextField(Integer.toString(s), 4));
    add(end = new CardinalTextField(Integer.toString(e), 4));
}
 
Example #29
Source File: DrawTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
    this.target = target;
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    target.setForeground(Color.red);
    CheckboxGroup group = new CheckboxGroup();
    Checkbox b;
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.red);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.green);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.blue);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.pink);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.orange);
    add(b = new Checkbox(null, group, true));
    b.addItemListener(this);
    b.setForeground(Color.black);
    target.setForeground(b.getForeground());
    Choice shapes = new Choice();
    shapes.addItemListener(this);
    shapes.addItem("Lines");
    shapes.addItem("Points");
    shapes.setBackground(Color.lightGray);
    add(shapes);
}
 
Example #30
Source File: DitherTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public DitherControls(DitherTest app, int s, int e, DitherMethod type,
        boolean vertical) {
    applet = app;
    setLayout(dcLayout);
    add(new Label(vertical ? "Vertical" : "Horizontal"));
    add(choice = new Choice());
    for (DitherMethod m : DitherMethod.values()) {
        choice.addItem(m.toString().substring(0, 1)
                + m.toString().substring(1).toLowerCase());
    }
    choice.select(type.ordinal());
    add(start = new CardinalTextField(Integer.toString(s), 4));
    add(end = new CardinalTextField(Integer.toString(e), 4));
}