Java Code Examples for javax.swing.JComponent

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project addis, under directory /application/src/main/java/org/drugis/addis/gui/builder/.

Source file: DrugView.java

  19 
vote

public static JComponent buildStudyListComponent(StudyListPresentation model,AddisWindow parent){
  JComponent studiesComp=null;
  if (model.getIncludedStudies().isEmpty()) {
    studiesComp=new JLabel("No studies found.");
  }
 else {
    studiesComp=new StudiesTablePanel(model,parent);
  }
  return studiesComp;
}
 

Example 2

From project autopsy, under directory /HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/.

Source file: HashDbManagementPanel.java

  18 
vote

@Override public Component prepareRenderer(TableCellRenderer renderer,int row,int column){
  Component c=super.prepareRenderer(renderer,row,column);
  JComponent jc=(JComponent)c;
  jc.setToolTipText((String)getValueAt(row,column));
  return c;
}
 

Example 3

From project beam-third-party, under directory /beam-meris-veg/src/main/java/org/esa/beam/processor/baer/ui/.

Source file: BaerUi.java

  18 
vote

/** 
 * Adds a parameter at the given position to tha panel supplied.
 * @param panel  the panel
 * @param name   the parameter name
 * @param line   the line
 * @param insets the top insets
 * @param gbc    the constraints
 */
private void addParameterToPanel(JPanel panel,String name,int line,int insets,GridBagConstraints gbc){
  Parameter param=_paramGroup.getParameter(name);
  GridBagUtils.setAttributes(gbc,"anchor=SOUTHWEST, fill=HORIZONTAL, weightx=1, gridy=" + String.valueOf(line++));
  if (insets > 0) {
    GridBagUtils.setAttributes(gbc,"insets.top=" + String.valueOf(insets));
  }
  JComponent label=param.getEditor().getLabelComponent();
  if (label != null) {
    GridBagUtils.addToPanel(panel,label,gbc);
  }
  GridBagUtils.setAttributes(gbc,"anchor=NORTHWEST, insets.top=0, gridy=" + String.valueOf(line++));
  GridBagUtils.addToPanel(panel,param.getEditor().getEditorComponent(),gbc);
}
 

Example 4

From project ceres, under directory /ceres-ui/src/main/java/com/bc/ceres/swing/binding/.

Source file: PropertyEditor.java

  18 
vote

/** 
 * Creates the editor component for the  {@link com.bc.ceres.binding.PropertyDescriptor} and bind itto a  {@link com.bc.ceres.binding.PropertyContainer} using the {@link BindingContext}.
 * @param propertyDescriptor The value descriptor
 * @param bindingContext The binding context
 * @return the editor component
 */
public JComponent[] createComponents(PropertyDescriptor propertyDescriptor,BindingContext bindingContext){
  JComponent editorComponent=createEditorComponent(propertyDescriptor,bindingContext);
  JLabel label=new JLabel(propertyDescriptor.getDisplayName() + ":");
  Binding binding=bindingContext.getBinding(propertyDescriptor.getName());
  binding.addComponent(label);
  return new JComponent[]{editorComponent,label};
}
 

Example 5

From project codjo-segmentation, under directory /codjo-segmentation-gui/src/main/java/net/codjo/segmentation/gui/settings/.

Source file: ClassificationStructureGui.java

  18 
vote

@Override public void dispose(){
  super.dispose();
  for (  Map.Entry<JComponent,ActionListener> entry : mapComponentListener.entrySet()) {
    JComponent loopComponent=entry.getKey();
    if (loopComponent instanceof JComboBox) {
      ((JComboBox)loopComponent).removeActionListener(entry.getValue());
    }
    if (loopComponent instanceof JCheckBox) {
      ((JCheckBox)loopComponent).removeActionListener(entry.getValue());
    }
  }
}
 

Example 6

From project codjo-standalone-common, under directory /src/main/java/net/codjo/utils/sql/.

Source file: AbstractDetailWindow.java

  18 
vote

/** 
 * Ajoute un ModificationListener  AbstractDetailWindow.
 * @param columnName Le ModificationListener  ajouter
 */
private void initModificationListener(String columnName){
  try {
    Field field=getDeclaredField(getClass(),columnName);
    Object fieldValue=field.get(this);
    if ((fieldValue instanceof JComponent) == false) {
      return;
    }
    JComponent component=(JComponent)fieldValue;
    ModificationListener oldML=(ModificationListener)component.getClientProperty("modificationListener");
    if (oldML != null) {
      oldML.clear();
      return;
    }
    if (component instanceof JTextComponent) {
      ModificationListener ml=new ModificationListener(component);
      ((JTextComponent)component).getDocument().addDocumentListener(ml);
      component.putClientProperty("modificationListener",ml);
    }
 else     if (component instanceof JComboBox) {
      ModificationListener ml=new ModificationListener(component);
      ((JComboBox)component).addActionListener(ml);
      component.putClientProperty("modificationListener",ml);
    }
 else     if (component instanceof JCheckBox) {
      ModificationListener ml=new ModificationListener(component);
      ((JCheckBox)component).addActionListener(ml);
      component.putClientProperty("modificationListener",ml);
    }
  }
 catch (  Exception nsfe) {
    nsfe.printStackTrace();
  }
}
 

Example 7

From project Calendar-Application, under directory /com/toedter/calendar/demo/.

Source file: JCalendarDemo.java

  17 
vote

/** 
 * Creates the menu bar
 * @return Description of the Return Value
 */
public JToolBar createToolBar(){
  toolBar=new JToolBar();
  toolBar.putClientProperty("jgoodies.headerStyle","Both");
  toolBar.setRollover(true);
  toolBar.setFloatable(false);
  for (int i=0; i < beans.length; i++) {
    Icon icon;
    JButton button;
    try {
      final JComponent bean=beans[i];
      URL iconURL=bean.getClass().getResource("images/" + bean.getName() + "Color16.gif");
      icon=new ImageIcon(iconURL);
      button=new JButton(icon);
      ActionListener actionListener=new ActionListener(){
        public void actionPerformed(        ActionEvent e){
          installBean(bean);
        }
      }
;
      button.addActionListener(actionListener);
    }
 catch (    Exception e) {
      System.out.println("JCalendarDemo.createToolBar(): " + e);
      button=new JButton(beans[i].getName());
    }
    button.setFocusPainted(false);
    toolBar.add(button);
  }
  return toolBar;
}
 

Example 8

From project coffeescript-netbeans, under directory /src/coffeescript/nb/project/sample/.

Source file: CoffeeScriptApplicationWizardIterator.java

  17 
vote

public void initialize(WizardDescriptor wiz){
  this.wiz=wiz;
  index=0;
  panels=createPanels();
  String[] steps=createSteps();
  for (int i=0; i < panels.length; i++) {
    Component c=panels[i].getComponent();
    if (steps[i] == null) {
      steps[i]=c.getName();
    }
    if (c instanceof JComponent) {
      JComponent jc=(JComponent)c;
      jc.putClientProperty("WizardPanel_contentSelectedIndex",new Integer(i));
      jc.putClientProperty("WizardPanel_contentData",steps);
    }
  }
}
 

Example 9

From project enclojure, under directory /netbeans/plugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/debugger/breakpoints/.

Source file: ClojureBreakpointActionsProvider.java

  17 
vote

private static void customize(Breakpoint b){
  JComponent c=null;
  if (b instanceof ClojureLineBreakpoint) {
    c=new ClojureBreakpointPanel((ClojureLineBreakpoint)b);
  }
  DialogDescriptor descriptor=new DialogDescriptor(c,NbBundle.getMessage(ClojureBreakpointActionsProvider.class,"CTL_Breakpoint_Customizer_Title"));
  JButton bOk=null;
  JButton bClose=null;
  descriptor.setOptions(new JButton[]{bOk=new JButton(NbBundle.getMessage(ClojureBreakpointActionsProvider.class,"CTL_Ok")),bClose=new JButton(NbBundle.getMessage(ClojureBreakpointActionsProvider.class,"CTL_Close"))});
  HelpCtx helpCtx=HelpCtx.findHelp(c);
  if (helpCtx == null)   helpCtx=new HelpCtx("debug.add.breakpoint");
  ;
  descriptor.setHelpCtx(helpCtx);
  bOk.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ClojureBreakpointActionsProvider.class,"ACSD_CTL_Ok"));
  bOk.setMnemonic(NbBundle.getMessage(ClojureBreakpointActionsProvider.class,"CTL_Ok_MNEM").charAt(0));
  bClose.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ClojureBreakpointActionsProvider.class,"ACSD_CTL_Close"));
  bClose.setMnemonic(NbBundle.getMessage(ClojureBreakpointActionsProvider.class,"CTL_Close_MNEM").charAt(0));
  descriptor.setClosingOptions(null);
  Dialog d=DialogDisplayer.getDefault().createDialog(descriptor);
  d.pack();
  d.setVisible(true);
  if (descriptor.getValue() == bOk) {
    ((Controller)c).ok();
  }
}
 

Example 10

From project Agot-Java, under directory /src/main/java/got/ui/.

Source file: FamilyCharacterDialog.java

  15 
vote

private JComponent familyCharacter(String charName){
  JPanel panel=new JPanel(false);
  panel.setLayout(new GridLayout(1,2));
  JLabel nameLabel=new JLabel(charName);
  panel.add(nameLabel);
  CharacterInfo characterInfo=node.getGameInfo().getCharacterMap().get(charName);
  String des=String.format("<html><B>Power</B> : %d <br><br> <B>Sword</B> : %d <br><br> <B>Sheild</B> : %d <br><br> <B>Speical</B> : %s <br><br></html>",characterInfo.getPower(),characterInfo.getSword(),characterInfo.getShield(),characterInfo.getSpecial());
  JLabel desLabel=new JLabel(des);
  panel.add(desLabel);
  return panel;
}
 

Example 11

From project beam-meris-icol, under directory /src/main/java/org/esa/beam/meris/icol/ui/.

Source file: IcolForm.java

  15 
vote

private void updateMerisCloudMaskExpressionEditor(JTextField textField,JComponent etcButton){
  Product selectedProduct=cloudProductSelector.getSelectedProduct();
  boolean hasProduct=selectedProduct != null;
  etcButton.setEnabled(hasProduct);
  textField.setEnabled(hasProduct);
  if (hasProduct) {
    Term term=null;
    try {
      term=BandArithmetic.parseExpression(textField.getText(),new Product[]{selectedProduct},0);
    }
 catch (    ParseException ignore) {
    }
    if (term == null) {
      textField.setText("");
    }
  }
}
 

Example 12

From project BMach, under directory /src/jsyntaxpane/util/.

Source file: SwingUtils.java

  15 
vote

/** 
 * FIXME:  These two addEscapeListener can be called on a new interface that implements RootPainCOntainer (Swing) and a new method that is called
 * @param dialog
 */
public static void addEscapeListener(final EscapeListener dialog){
  ActionListener escListener=new ActionListener(){
    @Override public void actionPerformed(    ActionEvent e){
      dialog.escapePressed();
    }
  }
;
  dialog.getRootPane().registerKeyboardAction(escListener,KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0),JComponent.WHEN_IN_FOCUSED_WINDOW);
}
 

Example 13

From project bndtools, under directory /bndtools.bndplugins/src/bndtools/bndplugins/repo/git/.

Source file: GitCredentialsProvider.java

  15 
vote

@Override public boolean get(URIish uri,CredentialItem... items) throws UnsupportedCredentialItem {
  Mapping mapping=repo.findMapping(uri.toString());
  if (mapping != null) {
    for (    CredentialItem item : items) {
      if (item instanceof CredentialItem.Username) {
        ((CredentialItem.Username)item).setValue(mapping.user);
        continue;
      }
      if (item instanceof CredentialItem.Password) {
        ((CredentialItem.Password)item).setValue(mapping.pass);
        continue;
      }
      if (item instanceof CredentialItem.StringType && item.isValueSecure()) {
        ((CredentialItem.StringType)item).setValue(new String(mapping.pass));
        continue;
      }
    }
    return true;
  }
  if (isInteractive()) {
    JComponent[] inputs=getSwingUI(items);
    int result=JOptionPane.showConfirmDialog(null,inputs,"Enter credentials for " + repo.getName(),JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE);
    if (result != JOptionPane.OK_OPTION) {
      return false;
    }
    updateCredentialItems(inputs);
    return true;
  }
  return false;
}
 

Example 14

From project ChkBugReport, under directory /src/com/sonyericsson/chkbugreport/.

Source file: Gui.java

  15 
vote

@Override public boolean canImport(JComponent comp,DataFlavor[] transferFlavors){
  for (  DataFlavor df : transferFlavors) {
    if (df.isMimeTypeEqual("text/uri-list")) {
      if ("java.lang.String".equals(df.getParameter("class"))) {
        return true;
      }
    }
  }
  return false;
}
 

Example 15

From project Cinch, under directory /example/com/palantir/ptoss/cinch/example/demo/.

Source file: DemoView.java

  15 
vote

private static JPanel panelOf(JComponent... comps){
  JPanel p=new JPanel();
  p.setOpaque(false);
  for (  JComponent comp : comps) {
    p.add(comp);
  }
  return p;
}
 

Example 16

From project Clotho-Core, under directory /ClothoFabApps/FabDash/src/org/clothocore/widget/fabdash/.

Source file: InventoryTransferHandler.java

  15 
vote

@Override public Transferable createTransferable(JComponent c){
  try {
    JTable t=(JTable)c;
    String toPackage=(String)t.getValueAt(t.getSelectedRow(),0);
    if (toPackage != null) {
      ObjBase toPackageObjBase=null;
      if (t.getName().contains("oligo")) {
        toPackageObjBase=Oligo.retrieveByName(toPackage);
      }
 else       if (t.getName().contains("part")) {
        toPackageObjBase=Part.retrieveByName(toPackage);
      }
 else       if (t.getName().contains("vector")) {
        toPackageObjBase=Vector.retrieveByName(toPackage);
      }
 else       if (t.getName().contains("plasmid")) {
        toPackageObjBase=Plasmid.retrieveByName(toPackage);
      }
      if (toPackageObjBase != null) {
        return new TransferableObject(toPackageObjBase);
      }
 else {
        return null;
      }
    }
 else {
      return null;
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
    return null;
  }
}
 

Example 17

From project codjo-control, under directory /codjo-control-gui/src/main/java/net/codjo/control/gui/plugin/.

Source file: DefaultQuarantineDetailWindow.java

  15 
vote

protected void addField(DetailDataSource detailDataSource,String fieldName,String label,JComponent comp,String tabName){
  comp.setName(this.getTitle() + "_" + label);
  addBasicField(label,comp,tabName);
  detailDataSource.declare(fieldName,comp);
  comp.setName(this.getTitle() + "_" + label);
}
 

Example 18

From project codjo-data-process, under directory /codjo-data-process-gui/src/main/java/net/codjo/dataprocess/gui/launcher/configuration/.

Source file: ConfigurationDialog.java

  15 
vote

private void initGui(){
  setSize(900,500);
  initTopPanel();
  initLeftPanel();
  initRightPanel();
  initBottomPanel();
  initMainPanel();
  getContentPane().setLayout(borderLayout);
  getContentPane().add(mainPanel,BorderLayout.CENTER);
  InputMap inputMap=mainPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
  inputMap.put(KeyStroke.getKeyStroke("ESCAPE"),"cancel");
  mainPanel.getActionMap().put("cancel",new AbstractAction(){
    public void actionPerformed(    ActionEvent evt){
      quitCommand();
    }
  }
);
  setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
  addWindowListener(new WindowAdapter(){
    @Override public void windowClosing(    WindowEvent evt){
      quitCommand();
    }
  }
);
  if (guiTreatmentList.getModel().getSize() != 0) {
    guiTreatmentList.setSelectedIndex(0);
  }
  trtConfigurationTable.getModel().addTableModelListener(new TableModelListener(){
    public void tableChanged(    TableModelEvent evt){
      modified=true;
    }
  }
);
}
 

Example 19

From project codjo-imports, under directory /codjo-imports-gui/src/main/java/net/codjo/imports/gui/.

Source file: FieldImportDetailWindow.java

  15 
vote

protected void addField(String fieldName,JLabel label,JComponent comp){
  if (comp instanceof JTextArea) {
    JTextArea textArea=(JTextArea)comp;
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    mainPanel.addItem(label,new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
  }
 else {
    mainPanel.addItem(label,comp);
  }
  dataSource.declare(fieldName,comp);
}
 

Example 20

From project dawn-common, under directory /org.dawb.hdf5/src/ncsa/hdf/view/.

Source file: DefaultTableView.java

  15 
vote

public void mouseClicked(MouseEvent e){
  if (!(isRegRef || isObjRef))   return;
  int eMod=e.getModifiers();
  if (e.isPopupTrigger() || (eMod == InputEvent.BUTTON3_MASK) || (System.getProperty("os.name").startsWith("Mac") && (eMod == (InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK)))) {
    if (popupMenu != null) {
      popupMenu.show((JComponent)e.getSource(),e.getX(),e.getY());
    }
  }
 else   if (e.getClickCount() == 2) {
    viewType=ViewType.TABLE;
    Object theData=getSelectedData();
    if (theData == null) {
      toolkit.beep();
      JOptionPane.showMessageDialog(this,"No data selected.",getTitle(),JOptionPane.ERROR_MESSAGE);
      return;
    }
    int len=Array.getLength(theData);
    for (int i=0; i < len; i++) {
      if (isRegRef)       showRegRefData((String)Array.get(theData,i));
 else       if (isObjRef)       showObjRefData(Array.getLong(theData,i));
    }
  }
}
 

Example 21

From project des, under directory /daemon/lib/apache-log4j-1.2.16/src/main/java/org/apache/log4j/lf5/viewer/.

Source file: LF5SwingUtils.java

  15 
vote

/** 
 * Work around for JTable/viewport bug.
 * @link http://developer.java.sun.com/developer/bugParade/bugs/4205145.html
 */
protected static void repaintLater(final JComponent component){
  SwingUtilities.invokeLater(new Runnable(){
    public void run(){
      component.repaint();
    }
  }
);
}
 

Example 22

From project drools-planner, under directory /drools-planner-examples/src/main/java/org/drools/planner/examples/common/swingui/.

Source file: SolverAndPersistenceFrame.java

  15 
vote

private JComponent createLoadUnsolvedPanel(){
  loadUnsolvedActionList=new ArrayList<Action>();
  JPanel panel=new JPanel(new GridLayout(0,1));
  for (  File file : solutionBusiness.getUnsolvedFileList()) {
    Action loadUnsolvedAction=new LoadAction(file);
    loadUnsolvedActionList.add(loadUnsolvedAction);
    panel.add(new JButton(loadUnsolvedAction));
  }
  JScrollPane scrollPane=new JScrollPane(panel);
  scrollPane.getVerticalScrollBar().setUnitIncrement(25);
  scrollPane.setPreferredSize(new Dimension(250,200));
  return scrollPane;
}
 

Example 23

From project drugis-common, under directory /common-extra/src/main/java/org/drugis/common/gui/.

Source file: ImageExporter.java

  15 
vote

public static void writeImage(Component frame,final JComponent p,final int width,final int height){
  String[] extensions={"png"};
  String[] descriptions={"PNG files"};
  FileSaveDialog dialog=new FileSaveDialog(frame,extensions,descriptions){
    @Override public void doAction(    String path,    String extension){
      if (extension.equals("png"))       writePNG(path,p,width,height);
 else       throw new IllegalArgumentException("Unknown extension " + extension);
    }
  }
;
  dialog.saveActions();
}
 

Example 24

From project en4j, under directory /NBPlatformApp/NoteContentViewModule/src/main/java/com/rubenlaguna/en4j/NoteContentViewModule/.

Source file: ENMLReplacedElementFactory.java

  15 
vote

private ReplacedElement loadImage(LayoutContext context,String hash){
  ReplacedElement toReturn=null;
  InputStream is=getImage(hash);
  Image image=null;
  if (is == null) {
    return brokenImage(context,100,100);
  }
  try {
    image=ImageIO.read(is);
  }
 catch (  IOException e) {
    LOG.log(Level.WARNING,"exception caught:",e);
  }
 finally {
    try {
      is.close();
    }
 catch (    IOException e) {
    }
  }
  if (image == null) {
    return brokenImage(context,100,100);
  }
  ImageIcon icon=new ImageIcon(image);
  JLabel cc=new JLabel(icon);
  cc.setSize(cc.getPreferredSize());
  FSCanvas canvas=context.getCanvas();
  if (canvas instanceof JComponent) {
    ((JComponent)canvas).add(cc);
  }
  toReturn=new SwingReplacedElement(cc){
    public boolean isRequiresInteractivePaint(){
      return false;
    }
  }
;
  return toReturn;
}