Java Code Examples for javax.swing.JComboBox#addItemListener()

The following examples show how to use javax.swing.JComboBox#addItemListener() . 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: LabeledComboBox.java    From incubator-iotdb with Apache License 2.0 6 votes vote down vote up
LabeledComboBox(Map<K, V> itemMap, ComboSelectedCallback callback, String labelText) {
  super(BoxLayout.Y_AXIS);

  JLabel label = new JLabel(labelText);
  add(label);

  Vector vector = new Vector(itemMap.keySet());
  vector.sort(null);
  comboBoxModel = new DefaultComboBoxModel(vector);
  comboBox = new JComboBox(comboBoxModel);
  comboBox.setSelectedIndex(-1);

  add(comboBox);

  comboBox.addItemListener(e -> {
    K key = (K) e.getItem();
    callback.call(itemMap.get(key));
  });
}
 
Example 2
Source File: PanelTableHeaderRenderer.java    From chipster with MIT License 6 votes vote down vote up
public PanelTableHeaderRenderer(ImportScreen screen, int i) {
	this.screen = screen;
	columnIndex = i;
	
	chipCombo = new JComboBox();
	titleLabel = new JLabel("Title");
	typeLabel = new JLabel("Type");
	
	chipCombo.addItemListener(this);
	//titleLabel.setForeground(UIManager.getColor("Label.disabledForeground"));
	
	
	this.setLayout(new BorderLayout());	
	
	Border border = UIManager.getBorder("TableHeader.cellBorder");
	border.getBorderInsets(this).set(5,5,5,5);
	setBorder(border);
			
	setBackground(UIManager.getColor("TableHeader.background"));

	add(titleLabel,BorderLayout.NORTH);
	add(typeLabel,BorderLayout.WEST);
	add(chipCombo,BorderLayout.EAST);
}
 
Example 3
Source File: ConnectionPanel.java    From Ardulink-2 with Apache License 2.0 6 votes vote down vote up
private JComboBox createURICombo() {
	JComboBox uris = new JComboBox();
	uris.setRenderer(new DefaultListCellRenderer() {

		private static final long serialVersionUID = 2756587449741341859L;

		@Override
		public Component getListCellRendererComponent(JList list,
				Object value, int index, boolean isSelected,
				boolean cellHasFocus) {
			return value == null ? null : super.getListCellRendererComponent(list,
					extractNameFromURI(URIs.newURI((String) value)), index,
					isSelected, cellHasFocus);
		}
	});
	uris.addItemListener(new ItemListener() {
		@Override
		public void itemStateChanged(ItemEvent event) {
			if (event.getStateChange() == SELECTED) {
				replaceSubpanel();
			}
		}
	});
	return uris;
}
 
Example 4
Source File: DriverGUI.java    From openAGV with Apache License 2.0 6 votes vote down vote up
/**
 * If a loopback adapter was chosen, this method initializes the combo boxes
 * with positions the user can set the vehicle to.
 *
 * @param rowIndex An index indicating which row this combo box belongs to
 * @param pointsCellEditor The <code>SingleCellEditor</code> containing
 * the combo boxes.
 */
private void initPointsComboBox(int rowIndex, SingleCellEditor pointsCellEditor) {
  final JComboBox<Point> pointComboBox = new JComboBox<>();

  objectService.fetchObjects(Point.class).stream()
      .sorted(Comparators.objectsByName())
      .forEach(point -> pointComboBox.addItem(point));
  pointComboBox.setSelectedIndex(-1);
  pointComboBox.setRenderer(new StringListCellRenderer<>(x -> x == null ? "" : x.getName()));

  pointComboBox.addItemListener((ItemEvent e) -> {
    Point newPoint = (Point) e.getItem();
    VehicleEntry vehicleEntry = vehicleEntryPool.getEntryFor(getSelectedVehicleName());
    if (vehicleEntry.getCommAdapter() instanceof SimVehicleCommAdapter) {
      SimVehicleCommAdapter adapter = (SimVehicleCommAdapter) vehicleEntry.getCommAdapter();
      adapter.initVehiclePosition(newPoint.getName());
    }
    else {
      LOG.debug("Vehicle {}: Not a simulation adapter -> not setting initial position.",
                vehicleEntry.getVehicle().getName());
    }
  });
  pointsCellEditor.setEditorAt(rowIndex, new DefaultCellEditor(pointComboBox));
}
 
Example 5
Source File: ParameterValueKeyCellEditor.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
private JComboBox<String> createParameterCombo(String operatorName, PropertyTable propertyTable) {
	JComboBox<String> combo = new JComboBox<>();

	Operator operator = process.getOperator((String) operatorCombo.getSelectedItem());
	if (operator != null) {
		Iterator<ParameterType> i = operator.getParameters().getParameterTypes().iterator();
		while (i.hasNext()) {
			combo.addItem(i.next().getKey());
		}
	}

	if (combo.getItemCount() == 0) {
		combo.addItem("no parameters");
	}

	combo.addItemListener(new ItemListener() {

		@Override
		public void itemStateChanged(ItemEvent e) {
			fireParameterChangedEvent();
			fireEditingStopped();
		}
	});

	combo.setSelectedIndex(0);

	return combo;
}
 
Example 6
Source File: GuiShowGovernanceAction.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
private void addComboBoxListener(JComboBox<Integer> comboBox, int numberOfOwnedBuildings, JLabel buildingIncome) {
	comboBox.addItemListener(new ItemListener() {
		
		@Override
		public void itemStateChanged(ItemEvent e) {
			buildingIncome.setText(Integer.toString(numberOfOwnedBuildings * (Integer)comboBox.getSelectedItem()));				
		}
	});
	buildingIncome.setText(Integer.toString(numberOfOwnedBuildings * (Integer)comboBox.getSelectedItem()));
}
 
Example 7
Source File: SwingStrategySelectionPanel.java    From atdl4j with MIT License 5 votes vote down vote up
public JPanel buildStrategySelectionPanel(Window aParentContainer, Atdl4jOptions atdl4jOptions)
{
	setAtdl4jOptions( atdl4jOptions );
	
	JPanel panel = new JPanel(new BorderLayout());
	// label
	JLabel strategiesDropDownLabel = new JLabel("Strategy");
	panel.add( strategiesDropDownLabel, BorderLayout.WEST );

	// dropDownList
	strategiesDropDown = new JComboBox();
	strategiesDropDown.setEditable( false );
	
	panel.add(strategiesDropDown, BorderLayout.CENTER);

	if ( Atdl4jConfig.getConfig().getStrategyDropDownItemDepth() != null )
	{
		strategiesDropDown.setMaximumRowCount( Atdl4jConfig.getConfig().getStrategyDropDownItemDepth().intValue() );
	}
	// tooltip
	strategiesDropDown.setToolTipText("Select a Strategy");
	// action listener
	strategiesDropDown.addItemListener( new ItemListener()	{

		@Override
		public void itemStateChanged(ItemEvent e) {
			if (e.getStateChange() == ItemEvent.SELECTED) {
			    firePreStrategySelectedEvent();
				int index = strategiesDropDown.getSelectedIndex();
				selectDropDownStrategy( index );
			}
		}
	} );

	return panel;
}
 
Example 8
Source File: QueryParameter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ComboParameter(JComboBox combo, String parameter, String encoding) {
    super(parameter, encoding);
    this.combo = combo;
    combo.setModel(new DefaultComboBoxModel());
    combo.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            fireStateChanged();
        }
    });
    original = (ParameterValue) combo.getSelectedItem();
}
 
Example 9
Source File: SearchPatternController.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Bind Match Type option to a combo box.
 *
 * @param comboBox Combo box to control and display the match type. The
 * model of the combo box can contain only items of type {@link MatchType}.
 * {@link MatchType#LITERAL} and {@link MatchType#REGEXP} are mandatory in
 * the model.
 *
 * @since api.search/1.11
 */
public void bindMatchTypeComboBox(@NonNull final JComboBox comboBox) {
    Parameters.notNull("comboBox", comboBox);                       //NOI18N

    boolean regexpFound = false, literalFound = false;
    for (int i = 0; i < comboBox.getItemCount(); i++) {
        if (comboBox.getItemAt(i) == MatchType.LITERAL) {
            literalFound = true;
        } else if (comboBox.getItemAt(i) == MatchType.REGEXP) {
            regexpFound = true;
        } else if (!(comboBox.getItemAt(i) instanceof MatchType)) {
            throw new IllegalArgumentException("Model of the combo "//NOI18N
                    + "box can contain only MatchType items");      //NOI18N
        }
    }
    if (!(regexpFound && literalFound)) {
        throw new IllegalArgumentException(
                "At least MatchType.LITERAL and MatchType.REGEXP " //NOI18N
                + "must be contained in the combo box model.");     //NOI18N
    }
    if (matchTypeComboBox != null) {
        throw new IllegalStateException(
                "Already bound with option MATCH_TYPE");            //NOI18N
    }
    this.matchTypeComboBox = comboBox;
    comboBox.setEditable(false);
    setMatchType(this.matchType); //update match type, check it is supported
    comboBox.setSelectedItem(matchType);
    comboBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            setMatchType((MatchType) comboBox.getSelectedItem());
        }
    });
}
 
Example 10
Source File: ComBoxEditor.java    From knife with MIT License 5 votes vote down vote up
public ComBoxEditor()
{
	m_ComboBox = new JComboBox();
	m_ComboBox.addItem("选项A");
	m_ComboBox.addItem("选项B");
	m_ComboBox.addItem("选项C");
	
	m_ComboBox.setSize(100,30);
	
	m_OutLable= new JLabel();
	m_OutLable.setLayout(null);
	m_OutLable.setBounds(0, 0, 120, 40);
	m_OutLable.add(m_ComboBox);
	m_ComboBox.setLocation(50, 50);
	
	//响应下拉列表的事件
	m_ComboBox.addItemListener(new ItemListener()
	{
		@Override
		public void itemStateChanged(ItemEvent e)
		{
			System.out.println("下拉列表的选中事件");
			if(e.getStateChange() == e.SELECTED)
			{
				//获取选择的值
				m_SelStr = (String)m_ComboBox.getSelectedItem();
				//结束选择
				fireEditingStopped();
			}
		}
	});
}
 
Example 11
Source File: CardsPanel.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
private JPanel createCardsPanel() {
    String comboBoxItems[] = new String[items.size()];
    for(int i = 0; i < items.size(); i++) {
        comboBoxItems[i] = items.get(i).getName();
    }
    cb = new JComboBox(comboBoxItems);
    cb.setEditable(false);
    cb.addItemListener(this);

    // Create the cards
    JPanel[] cards = new JPanel[items.size()];
    for(int i = 0; i < items.size(); i++) {
        cards[i] = items.get(i).getOptionsPanel();
        if(cards[i] == null) {
            cards[i] = new JPanel();
        }
    }

    // Create the panel that contains the cards
    cardsPanel = new JPanel(new CardLayout());
    helpButtonsCardsPanel = new JPanel(new CardLayout());
    for(int i = 0; i < items.size(); i++) {
        cardsPanel.add(cards[i], comboBoxItems[i]);

        JPanel singleButtonContainer = new JPanel(new BorderLayout());
        if(Help.existsHelpForClass(items.get(i).getClass())) {
            singleButtonContainer.add(Help.createHelpButton(items.get(i).getClass()));
        }
        helpButtonsCardsPanel.add(singleButtonContainer, comboBoxItems[i]);

    }

    return cardsPanel;
}
 
Example 12
Source File: FcdProPanel.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public void initializeGui() throws IOException, DeviceException {
	setLayout(new BorderLayout(3,3));
	JPanel center = new JPanel();
	add(center, BorderLayout.NORTH);
	center.setLayout(new BoxLayout(center, BoxLayout.X_AXIS));
	
	// LNA gain 10 default, -5 to +30 
	JLabel lblLna = new JLabel("LNA Gain");
	center.add(lblLna);
	cbLnaGain = new JComboBox(FCD1TunerController.lnaGain);
	center.add(cbLnaGain);
	cbLnaGain.addItemListener(this);
	
	// Mixer Gain 4dB or 12dB
	JLabel lblMix = new JLabel("    Mixer Gain");
	center.add(lblMix);
	cbMixerGain = new JComboBox(FCD1TunerController.mixerGain);
	
	center.add(cbMixerGain);
	cbMixerGain.addItemListener(this);
	
	// IF Gain 1 - -3dB or +6dB
	
	// Band
	JLabel lblband = new JLabel("    Band");
	center.add(lblband);
	bandValue = new JTextField();
	bandValue.setMinimumSize(new Dimension(40,10));
	bandValue.setEnabled(false);
	center.add(bandValue);
	
	// RF Filter - not needed 268Mhz vs 298Mhz
	JLabel rfFilter = new JLabel("    RF Filter");
	center.add(rfFilter);
	rfFilterValue = new JTextField();
	rfFilterValue.setMinimumSize(new Dimension(70,10));
	rfFilterValue.setEnabled(false);
	center.add(rfFilterValue);


}
 
Example 13
Source File: NiftyPreviewPanel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void createToolbar() {
    JToolBar toolBar = new JToolBar();
    toolBar.setPreferredSize(new Dimension(10000, 24));
    toolBar.setMaximumSize(new Dimension(10000, 24));
    toolBar.setFloatable(false);
    JComboBox comboBox = new JComboBox(new String[]{"640x480", "480x800","800x480", "800x600", "1024x768", "1280x720"});
    comboBox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            String string = (String) e.getItem();
            final int width;
            final int height;
            if ("640x480".equals(string)) {
                width = 640;
                height = 480;
            } else if ("1024x768".equals(string)) {
                width = 1024;
                height = 768;
            } else if ("1280x720".equals(string)) {
                width = 1280;
                height = 720;
            } else if ("800x600".equals(string)) {
                width = 800;
                height = 600;
            } else if ("800x480".equals(string)) {
                width = 800;
                height = 480;
            } else if ("480x800".equals(string)) {
                width = 480;
                height = 800;
            } else {
                width = 640;
                height = 480;
            }
            offPanel.resizeGLView(width, height);
            SceneApplication.getApplication().enqueue(new Callable<Object>() {

                public Object call() throws Exception {
                    niftyDisplay.reshape(offPanel.getViewPort(), width, height);
                    return null;
                }
            });
            updatePreView(screen);
        }
    });
    toolBar.add(comboBox);
    toolBar.add(new JPanel());
    add(toolBar);
}
 
Example 14
Source File: ConnectionAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void initComponents() {
    setLayout(new BorderLayout(4, 0));
    setBorder(new EmptyBorder(0, 2, 0, 8));
    setOpaque(false);
    setFocusTraversalPolicyProvider(true);
    setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
        @Override
        public Component getDefaultComponent(Container aContainer) {
            if (!SwingUtilities.isEventDispatchThread()) {
                return null;
            }
            final EditorCookie ec = actionContext.lookup(
                    EditorCookie.class);
            if (ec != null) {
                JEditorPane[] panes = ec.getOpenedPanes();
                if (panes != null) {
                    for (JEditorPane pane : panes) {
                        if (pane.isShowing()) {
                            return pane;
                        }
                    }
                }
            }

            return null;
        }
   });

    combo = new JComboBox();
    combo.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            DatabaseConnection dbconn = (DatabaseConnection)combo.getSelectedItem();
            combo.setToolTipText(dbconn != null ? dbconn.getDisplayName() : null);
        }
    });
    combo.setOpaque(false);
    combo.setModel(new DefaultComboBoxModel(
            new String[] { NbBundle.getMessage(ToolbarPresenter.class, "ConnectionAction.ToolbarPresenter.LoadingConnections") }));

    combo.setRenderer(new DatabaseConnectionRenderer());
    String accessibleName = NbBundle.getMessage(ConnectionAction.class, "LBL_DatabaseConnection");
    combo.getAccessibleContext().setAccessibleName(accessibleName);
    combo.getAccessibleContext().setAccessibleDescription(accessibleName);
    combo.setPreferredSize (new Dimension (400, combo.getPreferredSize ().height));

    add(combo, BorderLayout.CENTER);

    comboLabel = new JLabel();
    Mnemonics.setLocalizedText(comboLabel, NbBundle.getMessage(ConnectionAction.class, "LBL_ConnectionAction"));
    comboLabel.setOpaque(false);
    comboLabel.setLabelFor(combo);
    add(comboLabel, BorderLayout.WEST);
}
 
Example 15
Source File: UnregisterSkinChangeListener.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Creates the main frame for <code>this</code> sample.
 */
public UnregisterSkinChangeListener() {
    super("Register skin change listener");

    this.setLayout(new BorderLayout());

    JPanel panel = new JPanel(new FlowLayout());

    // Get all skin display names and set the vector as a model
    // for combobox.
    final JComboBox<String> cb = new JComboBox<>(
            new Vector<>(SubstanceCortex.GlobalScope.getAllSkins().keySet()));
    cb.setSelectedIndex(-1);

    cb.addItemListener((ItemEvent evt) -> {
        // Get the affected item
        final String item = (String) evt.getItem();

        if (evt.getStateChange() == ItemEvent.SELECTED) {
            SwingUtilities.invokeLater(() -> {
                try {
                    // Get the skin info object based on
                    // the selected skin display name
                    SkinInfo skinInfo = SubstanceCortex.GlobalScope.getAllSkins().get(item);
                    // Set the global skin based on the
                    // skin class name.
                    SubstanceCortex.GlobalScope.setSkin(skinInfo.getClassName());
                    SwingUtilities.updateComponentTreeUI(UnregisterSkinChangeListener.this);
                } catch (Exception exc) {
                }
            });
        }
    });

    panel.add(new JLabel("All skins:"));
    panel.add(cb);

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    final JButton unregisterListener = new JButton("Unregister listener");
    unregisterListener.addActionListener((ActionEvent e) -> SwingUtilities.invokeLater(() -> {
        unregisterListener.setEnabled(false);
        // unregister listener
        SubstanceCortex.GlobalScope.unregisterSkinChangeListener(listener);
    }));
    controls.add(unregisterListener);
    this.add(controls, BorderLayout.SOUTH);

    this.add(panel, BorderLayout.CENTER);

    // register listener
    SubstanceCortex.GlobalScope.registerSkinChangeListener(listener = () -> {
        // show dialog with skin changed message.
        SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(UnregisterSkinChangeListener.this, "Skin changed"));
    });

    this.setSize(400, 200);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
 
Example 16
Source File: SummaryViewer.java    From moa with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor.
 * @param summaryTable
 * @param summary
 * @throws HeadlessException
 */
public SummaryViewer(SummaryTable[] summaryTable, Summary summary, String resultsPath) throws HeadlessException {
    super("Summary Viewer");

    setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    this.summaryTable = summaryTable;
    this.summary = summary;
    this.resultsPath = resultsPath;
    JLabel label = new JLabel("Summary");
    tableSummary = new JTable();
    String op[] = new String[this.summaryTable.length];
    for (int i = 0; i < this.summaryTable.length; i++) {
        op[i] = this.summaryTable[i].measureName;
    }
    tableSummary.setModel(new javax.swing.table.DefaultTableModel(
            this.summaryTable[0].value,
            this.summaryTable[0].algNames
    ));
    scroll = new JScrollPane();
    scroll.setViewportView(tableSummary);
    JPanel panel = new JPanel();
    JPanel main = new JPanel();
    jTablePanel = new JPanel();
    jTablePanel.setLayout(new GridLayout(1, 0));
    jTablePanel.add(scroll);
    summaryType = new JComboBox(op);
    summaryType.setSelectedIndex(0);
    bntExport = new JButton("Export Summaries");
  
    summaryType.addItemListener(this::summaryTypeItemStateChanged);
    bntExport.addActionListener(this::btnExportActionPerformed);
    panel.add(label);
    panel.add(summaryType);
    panel.add(bntExport);

    main.setLayout(new BorderLayout());
    main.add(this.jTablePanel, BorderLayout.CENTER);
    main.add(panel, BorderLayout.SOUTH);

    setContentPane(main);

    // Display the window.
    pack();
    setSize(700, 500);

    setVisible(true);
}
 
Example 17
Source File: FontEditor.java    From lsdpatch with MIT License 4 votes vote down vote up
public FontEditor() {
      setTitle("Font Editor");
      setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
      setBounds(100, 100, 415, 324);
      setResizable(false);

      JMenuBar menuBar = new JMenuBar();
      setJMenuBar(menuBar);

      JMenu mnFile = new JMenu("File");
mnFile.setMnemonic(KeyEvent.VK_F);
      menuBar.add(mnFile);

      JMenuItem mntmOpen = new JMenuItem("Open...");
mntmOpen.setMnemonic(KeyEvent.VK_O);
      mntmOpen.addActionListener(this);
      mnFile.add(mntmOpen);

      JMenuItem mntmSave = new JMenuItem("Save...");
mntmSave.setMnemonic(KeyEvent.VK_S);
      mntmSave.addActionListener(this);
      mnFile.add(mntmSave);

      JMenu mnEdit = new JMenu("Edit");
mnEdit.setMnemonic(KeyEvent.VK_E);
      menuBar.add(mnEdit);

      JMenuItem mntmCopy = new JMenuItem("Copy Tile");
      mntmCopy.addActionListener(this);
      mntmCopy.setMnemonic(KeyEvent.VK_C);
      mnEdit.add(mntmCopy);

      JMenuItem mntmPaste = new JMenuItem("Paste Tile");
      mntmPaste.setMnemonic(KeyEvent.VK_P);
      mntmPaste.addActionListener(this);
      mnEdit.add(mntmPaste);

      contentPane = new JPanel();
      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      setContentPane(contentPane);
      contentPane.setLayout(null);

      fontMap = new FontMap();
      fontMap.setBounds(10, 42, 128, 146);
      fontMap.setTileSelectListener(this);
      contentPane.add(fontMap);

      tileEditor = new TileEditor();
      tileEditor.setBounds(148, 11, 240, 240);
      tileEditor.setTileChangedListener(this);
      contentPane.add(tileEditor);

      fontSelector = new JComboBox();
      fontSelector.setBounds(10, 11, 128, 20);
      fontSelector.setEditable(true);
      fontSelector.addItemListener(this);
      fontSelector.addActionListener(this);
      contentPane.add(fontSelector);

      color1 = new JRadioButton("1");
      color1.setBounds(10, 220, 37, 23);
      color1.addItemListener(this);
      color1.setMnemonic(KeyEvent.VK_1);
      contentPane.add(color1);

      color2 = new JRadioButton("2");
      color2.setBounds(49, 220, 37, 23);
      color2.addItemListener(this);
      color2.setMnemonic(KeyEvent.VK_2);
      contentPane.add(color2);

      color3 = new JRadioButton("3");
      color3.setBounds(88, 220, 37, 23);
      color3.addItemListener(this);
      color3.setSelected(true);
      color3.setMnemonic(KeyEvent.VK_3);
      contentPane.add(color3);

      colorGroup = new javax.swing.ButtonGroup();
      colorGroup.add(color1);
      colorGroup.add(color2);
      colorGroup.add(color3);

      JLabel lblColor = new JLabel("Color:");
      lblColor.setBounds(10, 199, 46, 14);
      contentPane.add(lblColor);
  }
 
Example 18
Source File: RegisterSkinChangeListener.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Creates the main frame for <code>this</code> sample.
 */
public RegisterSkinChangeListener() {
    super("Register skin change listener");

    this.setLayout(new BorderLayout());

    JPanel panel = new JPanel(new FlowLayout());

    // Get all skin display names and set the vector as a model
    // for combobox.
    final JComboBox<String> cb = new JComboBox<>(
            new Vector<>(SubstanceCortex.GlobalScope.getAllSkins().keySet()));
    cb.setSelectedIndex(-1);

    cb.addItemListener((ItemEvent evt) -> {
        // Get the affected item
        final Object item = evt.getItem();

        if (evt.getStateChange() == ItemEvent.SELECTED) {
            SwingUtilities.invokeLater(() -> {
                try {
                    // Get the skin info object based on the selected skin display name
                    SkinInfo skinInfo = SubstanceCortex.GlobalScope.getAllSkins().get(item);
                    // Set the global skin based on the skin class name.
                    SubstanceCortex.GlobalScope.setSkin(skinInfo.getClassName());
                    SwingUtilities.updateComponentTreeUI(RegisterSkinChangeListener.this);
                } catch (Exception exc) {
                }
            });
        }
    });

    panel.add(new JLabel("All skins:"));
    panel.add(cb);

    this.add(panel, BorderLayout.CENTER);

    // register listener to show a dialog with skin changed message.
    SubstanceCortex.GlobalScope
            .registerSkinChangeListener(() -> SwingUtilities.invokeLater(() -> JOptionPane
                    .showMessageDialog(RegisterSkinChangeListener.this, "Skin changed")));

    this.setSize(400, 200);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
 
Example 19
Source File: ShapefileAssistantPage3.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Component createPageComponent() {
    mapPanel = new JPanel(new BorderLayout());
    mapLabel = new JLabel();
    mapLabel.setHorizontalAlignment(JLabel.CENTER);
    mapPanel.add(mapLabel, BorderLayout.CENTER);

    LayerSourcePageContext context = getContext();
    String filePath = (String) context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FILE_PATH);
    String fileName = new File(filePath).getName();

    infoLabel = new JLabel();

    styleList = new JComboBox();
    styleList.setRenderer(new StyleListCellRenderer());
    styleList.addItemListener(new StyleSelectionListener());
    styleList.setPreferredSize(new Dimension(100, styleList.getPreferredSize().height));

    JPanel panel2 = new JPanel(new BorderLayout(4, 4));
    panel2.setBorder(new EmptyBorder(4, 4, 4, 4));
    panel2.add(new JLabel("Style:"), BorderLayout.WEST);
    panel2.add(styleList, BorderLayout.EAST);

    JPanel panel3 = new JPanel(new BorderLayout(4, 4));
    panel3.setBorder(new EmptyBorder(4, 4, 4, 4));
    panel3.add(new JLabel(String.format("<html><b>%s</b>", fileName)), BorderLayout.CENTER);
    panel3.add(panel2, BorderLayout.EAST);

    JPanel panel = new JPanel(new BorderLayout(4, 4));
    panel.setBorder(new EmptyBorder(4, 4, 4, 4));
    panel.add(panel3, BorderLayout.NORTH);
    panel.add(mapPanel, BorderLayout.CENTER);
    panel.add(infoLabel, BorderLayout.SOUTH);

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            updateMap();
        }
    });
    return panel;
}
 
Example 20
Source File: ScreenInfoPanel.java    From hprof-tools with MIT License 4 votes vote down vote up
public ScreenInfoPanel(@Nonnull final TabbedInfoWindow mainWindow, @Nonnull List<Screen> screens) {
    super(new BorderLayout());

    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem item = new JMenuItem("Inspect View");
    item.addActionListener(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            mainWindow.showInstancesListTab(rightClickedViewed.getClassName(), Collections.singletonList(rightClickedViewed.getInstance()));
        }
    });
    popupMenu.add(item);

    imagePanel = new ImagePanel();
    viewTree = new JTree(new DefaultMutableTreeNode("Loading..."));
    viewTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    viewTree.addTreeSelectionListener(this);
    viewTree.addMouseListener(new PopupListener(popupMenu));
    JScrollPane treeScroller = new JScrollPane(viewTree);

    rootPicker = new JComboBox(new Vector<Object>(screens));
    rootPicker.addItemListener(this);

    JPanel settingsPanel = new JPanel(new GridLayout(1, 2));
    showBoundsBox = new JCheckBox("Show layout bounds", true);
    showBoundsBox.addItemListener(this);
    forceAlpha = new JCheckBox("Force alpha", true);
    forceAlpha.addItemListener(this);
    settingsPanel.add(showBoundsBox);
    settingsPanel.add(forceAlpha);
    settingsPanel.setBorder(new EmptyBorder(10, 0, 0, 0));

    infoTable = new JTable();
    infoTable.setRowSelectionAllowed(false);
    infoTable.setColumnSelectionAllowed(false);
    infoTable.setCellSelectionEnabled(false);
    infoTable.setShowGrid(true);

    JPanel bottomPanel = new JPanel(new BorderLayout());
    bottomPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
    bottomPanel.add(infoTable, BorderLayout.CENTER);
    bottomPanel.add(infoTable.getTableHeader(), BorderLayout.NORTH);
    bottomPanel.add(settingsPanel, BorderLayout.SOUTH);

    JPanel leftPanel = new JPanel(new BorderLayout());
    leftPanel.add(rootPicker, BorderLayout.NORTH);
    leftPanel.add(treeScroller, BorderLayout.CENTER);
    leftPanel.add(bottomPanel, BorderLayout.SOUTH);

    // Split pane for the tree and image views
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setLeftComponent(leftPanel);
    splitPane.setRightComponent(imagePanel);
    add(splitPane, BorderLayout.CENTER);
    selectedScreen = screens.get(0);
    update();
}