List of usage examples for javax.swing JComponent add
public Component add(Component comp)
From source file:Main.java
public static void swapComponentsAndResizeUI(JComponent ui, JComponent current, JComponent next) { ui.remove(current);/* ww w .j av a 2s . c o m*/ ui.add(next); current = next; Component c = ui.getTopLevelAncestor(); if (c instanceof Window) { Window w = (Window) c; w.pack(); } }
From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java
/** * Put all StatisticGrafic instances into panel. * Store panel as StatisticGrafic.statisticPanel. * @param panel/*from ww w .j av a 2 s . c om*/ */ public static void updateInit(Model model, String viewId, JComponent panel) { //System.out.println("StatisticGrafic.updateInit "); StatisticGrafic.statisticPanel = panel; panel.removeAll(); String[] id = model.getStatistics().getAllIds(); for (int i = 0; i < id.length; i++) { Statistic statistik = model.getStatistics().get(id[i]); StatisticGrafic statistikGrafic = (StatisticGrafic) statistik.getGrafic(); if (statistikGrafic != null && statistikGrafic.getViewId().equals(viewId)) { statistikGrafic.transform(); panel.add(statistikGrafic); //System.out.println("StatisticGrafic.updateInit "+statistik.getId()); } } }
From source file:SimpleAuthenticator.java
protected PasswordAuthentication getPasswordAuthentication() { // given a prompt? String prompt = getRequestingPrompt(); if (prompt == null) prompt = "Please login..."; // protocol// w ww. j a v a 2 s. c o m String protocol = getRequestingProtocol(); if (protocol == null) protocol = "Unknown protocol"; // get the host String host = null; InetAddress inet = getRequestingSite(); if (inet != null) host = inet.getHostName(); if (host == null) host = "Unknown host"; // port String port = ""; int portnum = getRequestingPort(); if (portnum != -1) port = ", port " + portnum + " "; // Build the info string String info = "Connecting to " + protocol + " mail service on host " + host + port; //JPanel d = new JPanel(); // XXX - for some reason using a JPanel here causes JOptionPane // to display incorrectly, so we workaround the problem using // an anonymous JComponent. JComponent d = new JComponent() { }; GridBagLayout gb = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); d.setLayout(gb); c.insets = new Insets(2, 2, 2, 2); c.anchor = GridBagConstraints.WEST; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 0.0; d.add(constrain(new JLabel(info), gb, c)); d.add(constrain(new JLabel(prompt), gb, c)); c.gridwidth = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; d.add(constrain(new JLabel("Username:"), gb, c)); c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0; String user = getDefaultUserName(); JTextField username = new JTextField(user, 20); d.add(constrain(username, gb, c)); c.gridwidth = 1; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.EAST; c.weightx = 0.0; d.add(constrain(new JLabel("Password:"), gb, c)); c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0; JPasswordField password = new JPasswordField("", 20); d.add(constrain(password, gb, c)); // XXX - following doesn't work if (user != null && user.length() > 0) password.requestFocus(); else username.requestFocus(); int result = JOptionPane.showConfirmDialog(frame, d, "Login", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.OK_OPTION) return new PasswordAuthentication(username.getText(), password.getText()); else return null; }
From source file:de.interactive_instruments.ShapeChange.UI.DefaultDialog.java
public void initialise(Converter c, Options o, ShapeChangeResult r, String m) { converter = c;/* w w w. j a v a2s .co m*/ options = o; result = r; mdl = m; // frame setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComponent newContentPane = new JPanel(new BorderLayout()); newContentPane.setOpaque(true); setContentPane(newContentPane); // pane JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab("Main options", createTab1()); tabbedPane.addTab("Secondary options", createTab2()); newContentPane.add(tabbedPane); // frame size int height = 480; int width = 720; pack(); Insets fI = getInsets(); setSize(width + fI.right + fI.left, height + fI.top + fI.bottom); Dimension sD = Toolkit.getDefaultToolkit().getScreenSize(); setLocation((sD.width - width) / 2, (sD.height - height) / 2); }
From source file:edu.uci.ics.jung.visualization.PluggableRenderContext.java
/** * @see edu.uci.ics.jung.visualization.RenderContext#setScreenDevice(edu.uci.ics.jung.visualization.VisualizationViewer) *//*from w ww. ja v a2 s . c o m*/ public void setScreenDevice(JComponent screenDevice) { this.screenDevice = screenDevice; screenDevice.add(rendererPane); }
From source file:net.sf.firemox.ui.component.CardPropertiesPanel.java
/** * Read and add from the given input stream the content of the given panel. * /* w ww. j av a 2s . c o m*/ * @param parent * the panel were the read content would be added. * @param dbStream * the source stream. * @throws Exception * If some I/O or reflection error occurs. */ private void fillTaskPane(final JComponent parent, final InputStream dbStream) throws IOException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { final int count = dbStream.read(); for (int i = 0; i < count; i++) { final int elementType = dbStream.read(); switch (elementType) { case NESTED_ELEMENT: final JTaskPaneGroup nested = new JTaskPaneGroup(); nested.setTitle(LanguageManagerMDB.getString(MToolKit.readString(dbStream))); fillTaskPane(nested, dbStream); parent.add(nested); break; case ATTRIBUTE: final Action action = (Action) Class .forName(new StringBuilder(TaskAction.class.getPackage().getName()).append(".") .append(StringUtils.capitalize(MToolKit.readString(dbStream))).append("Action") .toString()) .getConstructor(new Class[] { InputStream.class }).newInstance(new Object[] { dbStream }); ((JTaskPaneGroup) parent).add(action); break; default: throw new RuntimeException("unknown element type : " + elementType); } } }
From source file:greenfoot.gui.export.ExportPublishPane.java
/** * Creates the tag display with popular tags and an option to add tags *//*from w w w . j a v a2 s. co m*/ private JComponent getTagDisplay() { JComponent tagPanel = new JPanel(new MiksGridLayout(3, 1, 8, 8)); { tagPanel.setBackground(background); JComponent popPanel = new JPanel(new MiksGridLayout(8, 1, 8, 0)); popPanel.setBackground(background); JLabel popLabel = new JLabel(Config.getString("export.publish.tags.popular"), SwingConstants.LEADING); popLabel.setFont(font); popPanel.add(popLabel); for (int i = 0; i < popTags.length; i++) { JCheckBox popTag = new JCheckBox(Config.getString("export.publish.tags.loading")); popTag.setBackground(background); popTag.setFont(font); popTag.setEnabled(false); popTags[i] = popTag; popPanel.add(popTag); } tagPanel.add(popPanel); Box textPanel = new Box(BoxLayout.Y_AXIS); { JLabel additionalLabel = new JLabel(Config.getString("export.publish.tags.additional1"), SwingConstants.LEADING); additionalLabel.setFont(font); textPanel.add(additionalLabel); JLabel additionalLabel2 = new JLabel(Config.getString("export.publish.tags.additional2"), SwingConstants.CENTER); additionalLabel2.setFont(font); textPanel.add(additionalLabel2); } tagPanel.add(textPanel); tagArea = new JTextArea(); tagArea.setRows(3); JScrollPane tagScroller = new JScrollPane(tagArea); tagPanel.add(tagScroller); } return tagPanel; }
From source file:greenfoot.gui.export.ExportPublishPane.java
/** * Creates the scenario information display including information such as title, description, url. * For an update (isUpdate = true), the displayed options are slightly different. *///from w w w. j a v a2s . c om private void createScenarioDisplay() { leftPanel = new Box(BoxLayout.Y_AXIS); JLabel text; MiksGridLayout titleAndDescLayout = new MiksGridLayout(6, 2, 8, 8); titleAndDescLayout.setVerticallyExpandingRow(3); titleAndDescPanel = new JPanel(titleAndDescLayout); titleAndDescPanel.setBackground(background); if (imagePanel == null) { imagePanel = new ImageEditPanel(IMAGE_WIDTH, IMAGE_HEIGHT); imagePanel.setBackground(background); } Box textPanel = new Box(BoxLayout.Y_AXIS); { text = new JLabel(Config.getString("export.publish.image1")); text.setAlignmentX(Component.RIGHT_ALIGNMENT); text.setFont(font); textPanel.add(text); text = new JLabel(Config.getString("export.publish.image2")); text.setAlignmentX(Component.RIGHT_ALIGNMENT); text.setFont(font); textPanel.add(text); } titleAndDescPanel.add(textPanel); titleAndDescPanel.add(imagePanel); if (isUpdate) { text = new JLabel(Config.getString("export.snapshot.label"), SwingConstants.TRAILING); text.setFont(font); titleAndDescPanel.add(text); keepScenarioScreenshot = new JCheckBox(); keepScenarioScreenshot.setSelected(true); // "keep screenshot" defaults to true, therefore the image panel should be disabled imagePanel.enableImageEditPanel(false); keepScenarioScreenshot.setName(Config.getString("export.publish.keepScenario")); keepScenarioScreenshot.setOpaque(false); keepScenarioScreenshot.addChangeListener(this); titleAndDescPanel.add(keepScenarioScreenshot); } text = new JLabel(Config.getString("export.publish.title"), SwingConstants.TRAILING); text.setFont(font); titleAndDescPanel.add(text); String title = project.getName(); if (getTitle() != null) { title = getTitle(); } titleField = new JTextField(title); titleField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { String text = titleField.getText(); return text.length() > 0; } }); titleField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { checkForExistingScenario(); } }); titleAndDescPanel.add(titleField); // If there is an update a "changes" description area is shown. // If not there a short description and long description area are shown. if (isUpdate) { JLabel updateLabel = new JLabel(Config.getString("export.publish.update"), SwingConstants.TRAILING); updateLabel.setVerticalAlignment(SwingConstants.TOP); updateLabel.setFont(font); updateArea = new JTextArea(); updateArea.setRows(6); updateArea.setLineWrap(true); updateArea.setWrapStyleWord(true); JScrollPane updatePane = new JScrollPane(updateArea); titleAndDescPanel.add(updateLabel); titleAndDescPanel.add(updatePane); titleAndDescLayout.setVerticallyExpandingRow(4); } else { text = new JLabel(Config.getString("export.publish.shortDescription"), SwingConstants.TRAILING); text.setFont(font); shortDescriptionField = new JTextField(); titleAndDescPanel.add(text); titleAndDescPanel.add(shortDescriptionField); text = new JLabel(Config.getString("export.publish.longDescription"), SwingConstants.TRAILING); text.setVerticalAlignment(SwingConstants.TOP); text.setFont(font); descriptionArea = new JTextArea(); descriptionArea.setRows(6); descriptionArea.setLineWrap(true); descriptionArea.setWrapStyleWord(true); JScrollPane description = new JScrollPane(descriptionArea); titleAndDescPanel.add(text); titleAndDescPanel.add(description); } text = new JLabel(Config.getString("export.publish.url"), SwingConstants.TRAILING); text.setFont(font); titleAndDescPanel.add(text); urlField = new JTextField(); titleAndDescPanel.add(urlField); leftPanel.add(titleAndDescPanel, BorderLayout.SOUTH); JComponent sourceAndLockPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 8, 0)); { sourceAndLockPanel.setBackground(background); includeSource = new JCheckBox(Config.getString("export.publish.includeSource")); includeSource.setOpaque(false); includeSource.setSelected(false); includeSource.setFont(font); sourceAndLockPanel.add(includeSource); lockScenario.setFont(font); sourceAndLockPanel.add(lockScenario); sourceAndLockPanel.setMaximumSize(sourceAndLockPanel.getPreferredSize()); } leftPanel.add(sourceAndLockPanel, BorderLayout.SOUTH); }
From source file:greenfoot.gui.export.ExportPublishPane.java
/** * Creates a login panel with a username and password and a create account option * @return Login panel Component/*from w w w . ja va 2s.c o m*/ */ private JComponent getLoginPanel() { JComponent loginPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 8, 4)); loginPanel.setBackground(background); loginPanel.setAlignmentX(LEFT_ALIGNMENT); Border border = BorderFactory.createCompoundBorder(BorderFactory.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(12, 12, 12, 12)); loginPanel.setBorder(border); JLabel text = new JLabel(Config.getString("export.publish.login")); text.setForeground(headingColor); text.setVerticalAlignment(SwingConstants.TOP); loginPanel.add(text); text = new JLabel(Config.getString("export.publish.username"), SwingConstants.TRAILING); text.setFont(font); loginPanel.add(text); userNameField = new JTextField(10); userNameField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { String text = userNameField.getText(); return text.length() > 0; } }); userNameField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { checkForExistingScenario(); } }); loginPanel.add(userNameField); text = new JLabel(Config.getString("export.publish.password"), SwingConstants.TRAILING); text.setFont(font); loginPanel.add(text); passwordField = new JPasswordField(10); loginPanel.add(passwordField); JLabel createAccountLabel = new JLabel(Config.getString("export.publish.createAccount")); { createAccountLabel.setBackground(background); createAccountLabel.setHorizontalAlignment(SwingConstants.RIGHT); GreenfootUtil.makeLink(createAccountLabel, createAccountUrl); } loginPanel.add(createAccountLabel); return loginPanel; }
From source file:com.rapidminer.template.gui.RoleRequirementSelector.java
public RoleRequirementSelector(final TemplateController controller) { super(new BorderLayout()); setBorder(border);/*from w w w . j a va 2 s. c o m*/ this.controller = controller; setBackground(Color.WHITE); updateRequirement(); controller.getModel().addObserver(new Observer() { @Override public void update(Observable o, Object arg) { if (TemplateState.OBSERVER_EVENT_TEMPLATE.equals(arg)) { updateRequirement(); updateComponents(); } else if (TemplateState.OBSERVER_EVENT_ROLES.equals(arg)) { assignSelectionToCombo(); updateComponents(); attributeCombo.repaint(); } else if (TemplateState.OBSERVER_EVENT_INPUT.equals(arg)) { updateAttributes(); } } }); AutoCompleteDecorator.decorate(attributeCombo); AutoCompleteDecorator.decorate(positiveClassCombo); attributeCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (areValuesAdjusting) { return; } assignRoles(); } }); positiveClassCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (areValuesAdjusting) { return; } assignRoles(); } }); helpLabel.setHorizontalAlignment(SwingConstants.CENTER); add(helpLabel, BorderLayout.PAGE_START); chartPanel = new ChartPanel(null, 250, 250, 100, 100, 360, 360, true, false, false, false, false, false); chartPanel.setMinimumDrawWidth(0); chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); chartPanel.setMinimumDrawHeight(0); chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); attributeCombo.setPreferredSize(new Dimension(100, 30)); attributeCombo.setMaximumSize(new Dimension(150, 30)); add(chartPanel, BorderLayout.CENTER); JComponent comboPanel = new JPanel(); comboPanel.setLayout(new BoxLayout(comboPanel, BoxLayout.PAGE_AXIS)); JComponent comboPanelAtt = new JPanel(); comboPanelAtt.setBackground(Color.WHITE); comboPanelAtt.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); JComponent comboPanelClass = new JPanel(); comboPanelClass.setBackground(Color.WHITE); comboPanelClass.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); positiveClassCombo.setPreferredSize(new Dimension(100, 30)); positiveClassCombo.setMaximumSize(new Dimension(150, 30)); positiveClassLabel.setLabelFor(positiveClassCombo); positiveClassLabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); positiveClassLabel.setToolTipText(positiveClassLabel.getText()); positiveClassLabel.setHorizontalAlignment(SwingConstants.RIGHT); columnLabel.setLabelFor(attributeCombo); columnLabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); columnLabel.setToolTipText(columnLabel.getText()); columnLabel.setHorizontalAlignment(SwingConstants.RIGHT); comboPanelAtt.add(columnLabel); comboPanelAtt.add(attributeCombo); comboPanelClass.add(positiveClassLabel); comboPanelClass.add(positiveClassCombo); comboPanel.add(comboPanelAtt); comboPanel.add(comboPanelClass); add(comboPanel, BorderLayout.SOUTH); updateComponents(); }