javax.swing.JComponent#add ( )源码实例Demo

下面列出了javax.swing.JComponent#add ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: EditorUI.java
protected JComponent createExtComponent() {
    setLineNumberEnabled(true); // enable line numbering

    // extComponent will be a panel
    JComponent ec = new JPanel(new BorderLayout());
    ec.putClientProperty(JTextComponent.class, component);

    // Add the scroll-pane with the component to the center
    JScrollPane scroller = new JScrollPane(component);
    scroller.getViewport().setMinimumSize(new Dimension(4,4));
    
    // remove default scroll-pane border, winsys will handle borders itself           
    scroller.setBorder(null);
    
    setGlyphGutter(new GlyphGutter(this));
    scroller.setRowHeaderView(glyphGutter);

    initGlyphCorner(scroller);
    
    ec.add(scroller);

    // Install the status-bar panel to the bottom
    ec.add(getStatusBar().getPanel(), BorderLayout.SOUTH);
    
    return ec;
}
 
源代码2 项目: visualvm   文件: MemorySamplerViewSupport.java
private void activateSearch() {
    JComponent panel = getBottomPanel();

    if (searchPanel == null) {
        searchPanel = SearchUtils.createSearchPanel(table);
        panel.add(searchPanel);
        Container parent = panel.getParent();
        parent.invalidate();
        parent.revalidate();
        parent.repaint();
    }

    panel.setVisible(true);

    searchPanel.setVisible(true);
    searchPanel.requestFocusInWindow();
}
 
源代码3 项目: binnavi   文件: CAddressSpaceNodeMenuBuilder.java
/**
 * Tells a plugin to create an extension to this menu.
 *
 * @param menu The menu the extensions are added to.
 * @param plugin The plugin to extend the menu.
 */
private void addPluginMenu(final JComponent menu, final IAddressSpaceMenuPlugin plugin) {
  // ESCA-JAVA0166: Catching Exception because we are calling a plugin method
  try {
    final List<JComponent> menuItems = plugin.extendAddressSpaceMenu(getPluginAddressSpaces());

    if (menuItems != null) {
      for (final JComponent menuItem : menuItems) {
        if (menuItem != null) {
          menu.add(menuItem);
        }
      }
    }
  } catch (final Exception exception) {
    CUtilityFunctions.logException(exception);

    final String innerMessage = "E00094: " + "Plugin caused an unexpected exception";
    final String innerDescription = CUtilityFunctions.createDescription(
        String.format("The plugin %s caused an unexpected exception.", plugin.getName()),
        new String[] {"The plugin contains a bug."}, new String[] {
            "The plugin probably behaves erroneously from this point on but it remains active"});

    NaviErrorDialog.show(getParent(), innerMessage, innerDescription, exception);
  }
}
 
源代码4 项目: visualvm   文件: ThreadsMemoryView.java
private void activateFilter() {
    JComponent panel = getBottomPanel();
    
    if (filterPanel == null) {
        filterPanel = FilterUtils.createFilterPanel(table, null);
        panel.add(filterPanel);
        Container parent = panel.getParent();
        parent.invalidate();
        parent.revalidate();
        parent.repaint();
    }
    
    panel.setVisible(true);
    
    filterPanel.setVisible(true);
    filterPanel.requestFocusInWindow();
}
 
源代码5 项目: visualvm   文件: MemorySamplerViewSupport.java
private void activateFilter() {
    JComponent panel = getBottomPanel();

    if (filterPanel == null) {
        filterPanel = FilterUtils.createFilterPanel(table, null);
        panel.add(filterPanel);
        Container parent = panel.getParent();
        parent.invalidate();
        parent.revalidate();
        parent.repaint();
    }

    panel.setVisible(true);

    filterPanel.setVisible(true);
    filterPanel.requestFocusInWindow();
}
 
源代码6 项目: netbeans   文件: DefaultPlugin.java
/**
 */
private static JComponent wrapDialogContent(JComponent comp,
                                            boolean selfResizing) {
    JComponent result;
    
    if ((comp.getBorder() != null) || selfResizing) {
        result = selfResizing ? new SelfResizingPanel() : new JPanel();
        result.setLayout(new GridLayout());
        result.add(comp);
    } else {
        result = comp;
    }
    result.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
    result.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_title_select_generator"));
    return result;
}
 
源代码7 项目: audiveris   文件: ShapeSet.java
private static void addColoredItem (JComponent top,
                                    JMenuItem item,
                                    Color color)
{
    if (color != null) {
        item.setForeground(color);
    } else {
        item.setForeground(Color.black);
    }

    top.add(item);
}
 
源代码8 项目: gcs   文件: SkillDefaultEditor.java
private void removeDefault() {
    JComponent parent = (JComponent) getParent();
    parent.remove(this);
    if (parent.getComponentCount() == 0) {
        parent.add(new SkillDefaultEditor());
    }
    parent.revalidate();
    parent.repaint();
    notifyActionListeners();
}
 
源代码9 项目: dragonwell8_jdk   文件: bug4337267.java
void injectComponent(JComponent p, JComponent c, boolean shape) {
    if (shape) {
        setShaping(c);
    }
    p.removeAll();
    p.add(c);
}
 
源代码10 项目: netbeans   文件: OWSMPoliciesEditor.java
@Override
public JComponent createWSEditorComponent( Node node )
        throws InvalidDataException
{
    if ( mySupport == null || myFileObject == null ){
        JComponent component = new JPanel();
        component.setLayout( new FlowLayout());
        component.add( new JLabel(NbBundle.getMessage( OWSMPoliciesEditor.class, 
                "ERR_NoPoliciesSupport")));             // NOI18N
        return component;
    }
    myPanel = new PoliciesVisualPanel( myPolicyIds , myFileObject );
    return myPanel;
}
 
源代码11 项目: netbeans   文件: GroovyJUnitTestWizard.java
private static JComponent wrapDialogContent(JComponent comp) {
    JComponent result;

    result = new SelfResizingPanel();
    result.setLayout(new GridLayout());
    result.add(comp);
    result.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
    result.getAccessibleContext().setAccessibleDescription(BUNDLE.getString("AD_title_select_generator")); //NOI18N
    return result;
}
 
源代码12 项目: arcgis-runtime-demo-java   文件: ClusterApp.java
/**
 * Creates and displays the UI, including the map, for this application.
 * 
 * @return the UI component.
 */
public JComponent createUI() {
  // application content
  JComponent contentPane = createContentPane();

  // map
  map = createMap();

  contentPane.add(map);

  return contentPane;
}
 
源代码13 项目: FancyBing   文件: ScoreDialog.java
private JTextField createEntry(String labelText, int cols, String toolTip,
                               JComponent labels, JComponent values)
{
    labels.add(createEntryLabel(labelText));
    JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
    JTextField field = new JTextField(cols);
    GuiUtil.setEditableFalse(field);
    field.setHorizontalAlignment(JTextField.CENTER);
    field.setToolTipText(i18n(toolTip));
    panel.add(field);
    values.add(panel);
    return field;
}
 
源代码14 项目: gemfirexd-oss   文件: GfxdTop.java
private static void createAndShowGUI(JPanel jtop) {
    JFrame frame = new JFrame("GfxdTop");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComponent contentPane = (JComponent) frame.getContentPane();
    contentPane.add(jtop, BorderLayout.CENTER);
    contentPane.setOpaque(true);
    contentPane.setBorder(new EmptyBorder(12, 12, 12, 12));
    frame.setContentPane(contentPane);

    frame.pack();
    frame.setVisible(true);
}
 
源代码15 项目: astor   文件: ConstantVoltageExample.java
public static JComponent createComponent() {
    JComponent container = new JPanel();
    container.setLayout(new BoxLayout(container, BoxLayout.LINE_AXIS));
    
    Chart chart1 = createChart("Voltage", 550, 450, LegendPosition.InsideNE, true);
    Chart chart2 = createChart("Error Covariance", 450, 450, LegendPosition.InsideNE, false);
    
    constantVoltageTest(chart1, chart2);

    container.add(new XChartPanel(chart1));
    container.add(new XChartPanel(chart2));
    
    container.setBorder(BorderFactory.createLineBorder(Color.black, 1));
    return container;
}
 
源代码16 项目: WorldGrower   文件: GuiMouseListener.java
private void addBuildAction(JComponent parentMenuItem, BuildAction buildAction, Function<BuildAction, Action> guiActionBuilder) {
	final JMenuItem buildMenuItem;
	if (canPlayerCharacterPerformBuildAction(buildAction)) {
		buildMenuItem = MenuFactory.createJMenuItem(guiActionBuilder.apply(buildAction), soundIdReader);
		buildMenuItem.setText(buildAction.getSimpleDescription() + "...");
		parentMenuItem.add(buildMenuItem);
	} else {
		buildMenuItem = createDisabledActionMenuItem(parentMenuItem, buildAction);
	}
	
	String tooltip = createTooltipForBuildAction(buildAction);
	buildMenuItem.setToolTipText(tooltip);
	addImageIcon(buildAction, buildMenuItem);
}
 
源代码17 项目: stendhal   文件: GeneralSettings.java
/**
 * Creates a drop-down selector for setting battle karma mode.
 */
private JComponent createCombatKarmaSelector() {
	int pad = SBoxLayout.COMMON_PADDING;

	final JLabel selectorLabel = new JLabel("Use karma in combat:");

	final JComboBox<String> selector = new JComboBox<>();
	for (final String mode : KARMA_SETTINGS) {
		selector.addItem(mode);
	}

	final RPObject player = StendhalClient.get().getPlayer();

	// use player attribute if available to set combat karma mode
	final String currentMode;
	if (player.has(COMBAT_KARMA) && KARMA_SETTINGS.contains(player.get(COMBAT_KARMA))) {
		currentMode = player.get(COMBAT_KARMA);
	} else {
		currentMode = KARMA_SETTINGS.get(1);
	}
	selector.setSelectedItem(currentMode);

	selector.addActionListener(new ActionListener() {
		/**
		 * Sends action to the server.
		 */
		@Override
		public void actionPerformed(ActionEvent e) {
			new SetCombatKarmaAction().sendAction(selector.getSelectedItem().toString());
		}
	});

	WtWindowManager.getInstance().registerSettingChangeListener("combat.karma",
			new SettingChangeListener() {
		/**
		 * Updates the GUI when setting is changed via slash command.
		 */
		@Override
		public void changed(final String newValue) {
			selector.setSelectedItem(newValue);
		}
	});

	final JComponent karmaBox = SBoxLayout.createContainer(SBoxLayout.VERTICAL, pad);
	final JComponent karmaHBox = SBoxLayout.createContainer(SBoxLayout.HORIZONTAL, pad);

	karmaHBox.add(selectorLabel);
	karmaHBox.add(selector);

	// tooltip info
	final String[][] tooltipData = {
			{"Never", KARMA_SETTINGS.get(0), "Karma will never be used."},
			{"Normal (default)", KARMA_SETTINGS.get(1), "Karma is used for stronger enemies."},
			{"Always", KARMA_SETTINGS.get(2), "Karma is used regardless of how strong or weak enemy is."}
	};

	final StringBuilder descr = new StringBuilder();
	descr.append("Karma can be used in combat to give a slight edge. It helps in three ways:");
	descr.append("<br>1) Increases attack strength.");
	descr.append("<br>2) Increases defense.");
	descr.append("<br>3) Increases chances of hitting enemy.");
	descr.append("<br><br>The following three settings define when karma is used in combat:");
	karmaHBox.setToolTipText(ConvenienceMapper.createTooltip(descr.toString(), tooltipData));

	karmaBox.add(karmaHBox);

	return karmaBox;
}
 
源代码18 项目: FancyBing   文件: Main.java
private static void addFiller(JComponent component)
{
    Box.Filler filler = GuiUtil.createFiller();
    filler.setAlignmentX(Component.LEFT_ALIGNMENT);
    component.add(filler);
}
 
源代码19 项目: Rails   文件: SplashWindow.java
public SplashWindow(boolean isLoad, String initDetailsText) {
    //quit directly when no visualization required
    //all visualization related attributes remain null then
    if ("no".equals(Config.get("splash.window.open"))) return;

    //calculate estimated duration for the respective steps
    cumulativeDuration = new long[STEP_DURATION.length];
    boolean isDockingLayout = "yes".equals(Config.get("or.window.dockablePanels"));
    for ( int i = 0; i < STEP_DURATION.length ; i++) {
        //only consider step if relevant for this setup
        if ( (isLoad || !STEP_GROUP_LOAD.contains(STEP_DURATION[i].labelConfigKey))
                &&
             (isDockingLayout || !STEP_GROUP_DOCKING_LAYOUT.contains(STEP_DURATION[i].labelConfigKey)) ) {
            totalDuration += STEP_DURATION[i].expectedDurationInMillis;
        }
        cumulativeDuration[i] = totalDuration;
    }

    //set up dynamic elements

    myWin = new JWindow();

    leftIcon = new JLabel();
    setIcon(leftIcon, ICONS[currentIconIndex][0]);
    leftIcon.setBorder(new CompoundBorder(new EmptyBorder(5,5,5,5),new EtchedBorder()));
    rightIcon = new JLabel();
    setIcon(rightIcon, ICONS[currentIconIndex][1]);
    rightIcon.setBorder(new CompoundBorder(new EmptyBorder(5,5,5,5),new EtchedBorder()));

    progressBar = new JProgressBar(0,(int)totalDuration);
    progressBar.setStringPainted(true);
    progressBar.setMinimum(0);

    stepLabel = new JLabel(" "); // needed in order to allocate vertical space
    stepLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
    stepLabel.setBorder(new EmptyBorder(5,5,5,5));

    //set up static elements

    JLabel railsLabel = new JLabel("Rails " +Config.getVersion());
    railsLabel.setFont(railsLabel.getFont().deriveFont(
            (float)2.0 * railsLabel.getFont().getSize()));
    railsLabel.setAlignmentX(Component.CENTER_ALIGNMENT);

    String commandTextKey = isLoad ? "Splash.command.loadGame" : "Splash.command.newGame";
    JLabel commandLabel = new JLabel(
            LocalText.getText(commandTextKey,initDetailsText));
    commandLabel.setFont(commandLabel.getFont().deriveFont(Font.BOLD));
    commandLabel.setAlignmentX(Component.CENTER_ALIGNMENT);

    //plug elements together and set up layout

    JPanel railsCommandPanel = new JPanel();
    railsCommandPanel.setLayout(new BoxLayout(railsCommandPanel, BoxLayout.Y_AXIS));
    railsCommandPanel.add(railsLabel);
    railsCommandPanel.add(commandLabel);
    railsCommandPanel.setBorder(new EmptyBorder(3,3,3,3));

    JPanel idPanel = new JPanel();
    idPanel.setLayout(new BoxLayout(idPanel, BoxLayout.X_AXIS));
    idPanel.add(leftIcon);
    idPanel.add(railsCommandPanel);
    idPanel.add(rightIcon);
    idPanel.setBorder(new EmptyBorder(3,3,3,3));

    JComponent contentPane = (JComponent)myWin.getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    contentPane.add(idPanel);
    contentPane.add(progressBar);
    contentPane.add(stepLabel);
    contentPane.setBorder(new CompoundBorder(new EtchedBorder(),new EmptyBorder(5,5,5,5)));

    //perform layout within the EDT
    //blocking call as further initialization requires the layout to be frozen
    try {
        SwingUtilities.invokeAndWait(new Thread() {
            @Override
            public void run() {
                myWin.pack();
                Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                myWin.setLocation(
                      (dim.width - myWin.getSize().width) / 2,
                      (dim.height - myWin.getSize().height) / 2
                );
                myWin.setVisible(true);
            }
        });
    } catch (Exception e) {}

    progressVisualizer = new ProgressVisualizer();
    notifyOfStep(DUMMY_STEP_START);
    progressVisualizer.start();
}
 
源代码20 项目: FancyBing   文件: MessageDialogs.java
private static void addFiller(JComponent component)
{
    Box.Filler filler = GuiUtil.createFiller();
    filler.setAlignmentX(Component.LEFT_ALIGNMENT);
    component.add(filler);
}