javax.swing.JTable#setDefaultEditor ( )源码实例Demo

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

源代码1 项目: marathonv5   文件: TableFTFEditDemo.java
public TableFTFEditDemo() {
    super(new GridLayout(1, 0));

    JTable table = new JTable(new MyTableModel());
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);

    // Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    // Set up stricter input validation for the integer column.
    table.setDefaultEditor(Integer.class, new IntegerEditor(0, 100));

    // If we didn't want this editor to be used for other
    // Integer columns, we'd do this:
    // table.getColumnModel().getColumn(3).setCellEditor(
    // new IntegerEditor(0, 100));

    // Add the scroll pane to this panel.
    add(scrollPane);
}
 
源代码2 项目: marathonv5   文件: TableDialogEditDemo.java
public TableDialogEditDemo() {
    super(new GridLayout(1, 0));

    JTable table = new JTable(new MyTableModel());
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);

    // Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    // Set up renderer and editor for the Favorite Color column.
    table.setDefaultRenderer(Color.class, new ColorRenderer(true));
    table.setDefaultEditor(Color.class, new ColorEditor());

    // Add the scroll pane to this panel.
    add(scrollPane);
}
 
源代码3 项目: CodenameOne   文件: PerformanceMonitor.java
/**
 *  Create the ButtonColumn to be used as a renderer and editor. The
 *  renderer and editor will automatically be installed on the TableColumn
 *  of the specified column.
 *
 *  @param table the table containing the button renderer/editor
 *  @param action the Action to be invoked when the button is invoked
 *  @param column the column to which the button renderer/editor is added
 */
public ButtonColumn(JTable table, Action action, int column)
{
        this.table = table;
        this.action = action;

        renderButton = new JButton();
        editButton = new JButton();
        editButton.setFocusPainted( false );
        editButton.addActionListener( this );
        originalBorder = editButton.getBorder();
        setFocusBorder( new LineBorder(Color.BLUE) );

        TableColumnModel columnModel = table.getColumnModel();
        columnModel.getColumn(column).setCellRenderer( this );
        columnModel.getColumn(column).setCellEditor( this );
        table.addMouseListener( this );
        table.setDefaultEditor(Action.class, this);
        table.setDefaultRenderer(Action.class, this);
}
 
源代码4 项目: snap-desktop   文件: Discrete1BandTabularForm.java
public Discrete1BandTabularForm(ColorManipulationForm parentForm) {
    this.parentForm = parentForm;
    tableModel = new ImageInfoTableModel();
    moreOptionsForm = new MoreOptionsForm(this, false);

    final JTable table = new JTable(tableModel);
    table.setRowSorter(new TableRowSorter<>(tableModel));
    table.setDefaultRenderer(Color.class, new ColorTableCellRenderer());
    table.setDefaultEditor(Color.class, new ColorTableCellEditor());
    table.getTableHeader().setReorderingAllowed(false);
    table.getColumnModel().getColumn(1).setPreferredWidth(140);
    table.getColumnModel().getColumn(3).setCellRenderer(new PercentageRenderer());

    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    final JScrollPane tableScrollPane = new JScrollPane(table);
    tableScrollPane.getViewport().setPreferredSize(table.getPreferredSize());
    contentPanel = tableScrollPane;
}
 
源代码5 项目: snap-desktop   文件: Continuous1BandTabularForm.java
public Continuous1BandTabularForm(final ColorManipulationForm parentForm) {
    this.parentForm = parentForm;
    tableModel = new ImageInfoTableModel();
    tableModelListener = e -> {
        tableModel.removeTableModelListener(tableModelListener);
        parentForm.applyChanges();
        tableModel.addTableModelListener(tableModelListener);
    };
    moreOptionsForm = new MoreOptionsForm(this, parentForm.getFormModel().canUseHistogramMatching());
    discreteCheckBox = new DiscreteCheckBox(parentForm);
    moreOptionsForm.addRow(discreteCheckBox);
    parentForm.getFormModel().modifyMoreOptionsForm(moreOptionsForm);

    final JTable table = new JTable(tableModel);
    table.setDefaultRenderer(Color.class, new ColorTableCellRenderer());
    table.setDefaultEditor(Color.class, new ColorTableCellEditor());
    table.getTableHeader().setReorderingAllowed(false);
    table.getColumnModel().getColumn(0).setPreferredWidth(140);
    table.getColumnModel().getColumn(1).setPreferredWidth(140);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    final JScrollPane tableScrollPane = new JScrollPane(table);
    tableScrollPane.getViewport().setPreferredSize(table.getPreferredSize());
    contentPanel = tableScrollPane;
}
 
源代码6 项目: Logisim   文件: AttrTable.java
public AttrTable(Window parent) {
	super(new BorderLayout());
	this.parent = parent;

	titleEnabled = true;
	title = new TitleLabel();
	title.setHorizontalAlignment(SwingConstants.CENTER);
	title.setVerticalAlignment(SwingConstants.CENTER);
	tableModel = new TableModelAdapter(parent, NULL_ATTR_MODEL);
	table = new JTable(tableModel);
	table.setDefaultEditor(Object.class, editor);
	table.setTableHeader(null);
	table.setRowHeight(20);

	Font baseFont = title.getFont();
	int titleSize = Math.round(baseFont.getSize() * 1.2f);
	Font titleFont = baseFont.deriveFont((float) titleSize).deriveFont(Font.BOLD);
	title.setFont(titleFont);
	Color bgColor = new Color(240, 240, 240);
	setBackground(bgColor);
	table.setBackground(bgColor);
	Object renderer = table.getDefaultRenderer(String.class);
	if (renderer instanceof JComponent) {
		((JComponent) renderer).setBackground(Color.WHITE);
	}

	JScrollPane tableScroll = new JScrollPane(table);

	this.add(title, BorderLayout.PAGE_START);
	this.add(tableScroll, BorderLayout.CENTER);
	LocaleManager.addLocaleListener(this);
	localeChanged();
}
 
源代码7 项目: WorldGrower   文件: DemandsDialog.java
public void initializeGUI(ImageInfoReader imageInfoReader, SoundIdReader soundIdReader) {
	DemandsModel worldModel = new DemandsModel(demands);
	JTable table = JTableFactory.createJTable(worldModel);
	table.setDefaultRenderer(ImageIds.class, new ImageTableRenderer(imageInfoReader));
	table.setAutoCreateRowSorter(true);
	table.setRowHeight(50);
	table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	table.getColumnModel().getColumn(0).setPreferredWidth(100);
	table.getColumnModel().getColumn(1).setPreferredWidth(200);
	table.getColumnModel().getColumn(2).setPreferredWidth(100);
	table.getRowSorter().toggleSortOrder(1);

	TableCellEditor fce = new PositiveIntegerCellEditor(JTextFieldFactory.createJTextField());
       table.setDefaultEditor(Integer.class, fce);
	
	JScrollPane scrollPane = JScrollPaneFactory.createScrollPane(table);
	scrollPane.setBounds(15, 15, 418, 700);
	addComponent(scrollPane);
	
	JPanel buttonPane = new JPanel();
	buttonPane.setOpaque(false);
	buttonPane.setBounds(0, 720, 428, 75);
	buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
	addComponent(buttonPane);
	
	JButton okButton = JButtonFactory.createButton("OK", imageInfoReader, soundIdReader);
	okButton.setActionCommand("OK");
	buttonPane.add(okButton);
	addActionHandlers(okButton, worldModel, this, demands);
	getRootPane().setDefaultButton(okButton);
	
	SwingUtils.makeTransparant(table, scrollPane);
}
 
源代码8 项目: netbeans   文件: VerifierSupport.java
private void createResultsPanel() {
    resultPanel = new JPanel();
    resultPanel.setLayout(new BorderLayout());
    resultPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black),
            _archiveName));
    
    // 508 compliance
    resultPanel.getAccessibleContext().setAccessibleName( NbBundle.getMessage(VerifierSupport.class,"Panel"));  // NOI18N
    resultPanel.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage(VerifierSupport.class,"This_is_a_panel")); // NOI18N
    
    // set up result table
    tableModel = new DefaultTableModel(columnNames, 0);
    table = new JTable(tableModel) {
        @Override
        public Component prepareRenderer(TableCellRenderer renderer,
                int rowIndex, int vColIndex) {
            Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
            if (c instanceof JComponent) {
                JComponent jc = (JComponent)c;
                jc.setToolTipText((String)getValueAt(rowIndex, vColIndex));
            }
            return c;
        }
    };

    // 508 for JTable
    table.getAccessibleContext().setAccessibleName( NbBundle.getMessage(VerifierSupport.class,"Table"));    // NOI18N
    table.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage(VerifierSupport.class,"This_is_a_table_of_items"));//NOI18N
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    tableScrollPane = new JScrollPane(table);
    Object [] row = {NbBundle.getMessage(VerifierSupport.class,"Wait"),NbBundle.getMessage(VerifierSupport.class,"Running_Verifier_Tool..."),NbBundle.getMessage(VerifierSupport.class,"Running...") };  // NOI18N
    tableModel.addRow(row);
    //table.sizeColumnsToFit(0);
    // 508 for JScrollPane
    tableScrollPane.getAccessibleContext().setAccessibleName( NbBundle.getMessage(VerifierSupport.class,"Scroll_Pane"));    // NOI18N
    tableScrollPane.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(VerifierSupport.class,"ScrollArea"));   // NOI18N
    sizeTableColumns();
    // make the cells uneditable
    JTextField field = new JTextField();
    // 508 for JTextField
    field.getAccessibleContext().setAccessibleName(
            NbBundle.getMessage(VerifierSupport.class,"Text_Field"));   // NOI18N
    field.getAccessibleContext().setAccessibleDescription(
            NbBundle.getMessage(VerifierSupport.class,"This_is_a_text_field")); // NOI18N
    table.setDefaultEditor(Object.class, new DefaultCellEditor(field) {
        @Override
        public boolean isCellEditable(EventObject anEvent) {
            return false;
        }
    });
    // add action listener to table to show details
    tableSelectionListener =  new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e){
            if (!e.getValueIsAdjusting()){
                if(table.getSelectionModel().isSelectedIndex(e.getLastIndex())){
                    setDetailText( table.getModel().getValueAt(e.getLastIndex(),1)+
                            "\n"+table.getModel().getValueAt(e.getLastIndex(),2));//NOI18N
                }else if(table.getSelectionModel().isSelectedIndex(e.getFirstIndex())){
                    setDetailText(table.getModel().getValueAt(e.getFirstIndex(),1)+
                            "\n"+table.getModel().getValueAt(e.getFirstIndex(),2));//NOI18N
                }
            }
        }
    };
    table.getSelectionModel().addListSelectionListener(tableSelectionListener);
    
    // create detail text area
    detailText = new JTextArea(4,50);
    // 508 for JTextArea
    detailText.getAccessibleContext().setAccessibleName( NbBundle.getMessage(VerifierSupport.class,"Text_Area"));   // NOI18N
    detailText.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage(VerifierSupport.class,"This_is_a_text_area"));//NOI18N
    detailText.setEditable(false);
    textScrollPane = new JScrollPane(detailText);
    // 508 for JScrollPane
    textScrollPane.getAccessibleContext().setAccessibleName(  NbBundle.getMessage(VerifierSupport.class,"Scroll_Pane"));    // NOI18N
    textScrollPane.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage(VerifierSupport.class,"ScrollListPane"));//NOI18N
    textScrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), NbBundle.getMessage(VerifierSupport.class,"Detail:")));// NOI18N
    
    //add the components to the panel
    createControlPanel();
    
    //Create a split pane with the two scroll panes in it.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
            tableScrollPane, textScrollPane);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(150);
    
    //Provide minimum sizes for the two components in the split pane
    Dimension minimumSize = new Dimension(100, 50);
    tableScrollPane.setMinimumSize(minimumSize);
    textScrollPane.setMinimumSize(minimumSize);
    
    resultPanel.add("North", controlPanel); //NOI18N
    resultPanel.add("Center", splitPane);   // NOI18N
}
 
源代码9 项目: netbeans   文件: VerifierSupport.java
private void createResultsPanel() {
    resultPanel = new JPanel();
    resultPanel.setLayout(new BorderLayout());
    resultPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black),
            _archiveName));
    
    // 508 compliance
    resultPanel.getAccessibleContext().setAccessibleName( NbBundle.getMessage(VerifierSupport.class,"Panel"));  // NOI18N
    resultPanel.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage(VerifierSupport.class,"This_is_a_panel")); // NOI18N
    
    // set up result table
    tableModel = new DefaultTableModel(columnNames, 0);
    table = new JTable(tableModel) {
        @Override
        public Component prepareRenderer(TableCellRenderer renderer,
                int rowIndex, int vColIndex) {
            Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
            if (c instanceof JComponent) {
                JComponent jc = (JComponent)c;
                jc.setToolTipText((String)getValueAt(rowIndex, vColIndex));
            }
            return c;
        }
    };

    // 508 for JTable
    table.getAccessibleContext().setAccessibleName( NbBundle.getMessage(VerifierSupport.class,"Table"));    // NOI18N
    table.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage(VerifierSupport.class,"This_is_a_table_of_items"));//NOI18N
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    tableScrollPane = new JScrollPane(table);
    Object [] row = {NbBundle.getMessage(VerifierSupport.class,"Wait"),NbBundle.getMessage(VerifierSupport.class,"Running_Verifier_Tool..."),NbBundle.getMessage(VerifierSupport.class,"Running...") };  // NOI18N
    tableModel.addRow(row);
    //table.sizeColumnsToFit(0);
    // 508 for JScrollPane
    tableScrollPane.getAccessibleContext().setAccessibleName( NbBundle.getMessage(VerifierSupport.class,"Scroll_Pane"));    // NOI18N
    tableScrollPane.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(VerifierSupport.class,"ScrollArea"));   // NOI18N
    sizeTableColumns();
    // make the cells uneditable
    JTextField field = new JTextField();
    // 508 for JTextField
    field.getAccessibleContext().setAccessibleName(
            NbBundle.getMessage(VerifierSupport.class,"Text_Field"));   // NOI18N
    field.getAccessibleContext().setAccessibleDescription(
            NbBundle.getMessage(VerifierSupport.class,"This_is_a_text_field")); // NOI18N
    table.setDefaultEditor(Object.class, new DefaultCellEditor(field) {
        @Override
        public boolean isCellEditable(EventObject anEvent) {
            return false;
        }
    });
    // add action listener to table to show details
    tableSelectionListener =  new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e){
            if (!e.getValueIsAdjusting()){
                if(table.getSelectionModel().isSelectedIndex(e.getLastIndex())){
                    setDetailText( table.getModel().getValueAt(e.getLastIndex(),1)+
                            "\n"+table.getModel().getValueAt(e.getLastIndex(),2));//NOI18N
                }else if(table.getSelectionModel().isSelectedIndex(e.getFirstIndex())){
                    setDetailText(table.getModel().getValueAt(e.getFirstIndex(),1)+
                            "\n"+table.getModel().getValueAt(e.getFirstIndex(),2));//NOI18N
                }
            }
        }
    };
    table.getSelectionModel().addListSelectionListener(tableSelectionListener);
    
    // create detail text area
    detailText = new JTextArea(4,50);
    // 508 for JTextArea
    detailText.getAccessibleContext().setAccessibleName( NbBundle.getMessage(VerifierSupport.class,"Text_Area"));   // NOI18N
    detailText.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage(VerifierSupport.class,"This_is_a_text_area"));//NOI18N
    detailText.setEditable(false);
    textScrollPane = new JScrollPane(detailText);
    // 508 for JScrollPane
    textScrollPane.getAccessibleContext().setAccessibleName(  NbBundle.getMessage(VerifierSupport.class,"Scroll_Pane"));    // NOI18N
    textScrollPane.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage(VerifierSupport.class,"ScrollListPane"));//NOI18N
    textScrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), NbBundle.getMessage(VerifierSupport.class,"Detail:")));// NOI18N
    
    //add the components to the panel
    createControlPanel();
    
    //Create a split pane with the two scroll panes in it.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
            tableScrollPane, textScrollPane);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(150);
    
    //Provide minimum sizes for the two components in the split pane
    Dimension minimumSize = new Dimension(100, 50);
    tableScrollPane.setMinimumSize(minimumSize);
    textScrollPane.setMinimumSize(minimumSize);
    
    resultPanel.add("North", controlPanel); //NOI18N
    resultPanel.add("Center", splitPane);   // NOI18N
}
 
源代码10 项目: LGoodDatePicker   文件: TableEditorsDemo.java
/**
 * Constructor, Set up the table instance, and add the table editors to the table.
 */
public TableEditorsDemo() {
    // Use a grid layout for the panel.
    super(new GridLayout(1, 0));

    // This decides how many clicks are required to edit a cell in the table editors demo.
    // (Set this to 1 or 2 clicks, as desired.)
    int clickCountToEdit = 1;

    // Create the table and the scroll pane.
    JTable table = new JTable(new DemoTableModel());
    JScrollPane scrollPane = new JScrollPane(table);
    this.add(scrollPane);

    // Set a background color for the table. Note that by default, the picker table editors 
    // will match the table background color. This is expected behavior for table editors.
    // Color matching can be turned off if desired, from the table editor class constructors.
    table.setBackground(new Color(190, 240, 255));

    // Set all the default table editors to start with the desired number of clicks.
    // The default table editors are the ones supplied by the JTable class.
    InternalUtilities.setDefaultTableEditorsClicks(table, clickCountToEdit);

    // Add table renderers and editors for the LocalDate, LocalTime, and LocalDateTime types.
    //
    // Note: The editors and renders for each type should be separate instances of the 
    // matching table editor class. Don't use the same instance as both a renderer and editor.
    // If you did, it would be immediately obvious because the cells would not render properly.
    table.setDefaultRenderer(LocalDate.class, new DateTableEditor());
    DateTableEditor dateEdit = new DateTableEditor();
    dateEdit.clickCountToEdit = clickCountToEdit;
    table.setDefaultEditor(LocalDate.class, dateEdit);

    table.setDefaultRenderer(LocalTime.class, new TimeTableEditor());
    TimeTableEditor timeEdit = new TimeTableEditor();
    timeEdit.clickCountToEdit = clickCountToEdit;
    table.setDefaultEditor(LocalTime.class, timeEdit);

    table.setDefaultRenderer(LocalDateTime.class, new DateTimeTableEditor());
    DateTimeTableEditor dateTimeEdit = new DateTimeTableEditor();
    dateTimeEdit.clickCountToEdit = clickCountToEdit;
    table.setDefaultEditor(LocalDateTime.class, dateTimeEdit);

    // Explicitly set the default editor instance (data type) for each column, by looking at 
    // the most common data type found in each column.
    zSetAllColumnEditorsAndRenderers(table);

    // Set the width of the DateTime column to be a bit bigger than the rest.
    table.getColumnModel().getColumn(DemoTableModel.dateTimeColumnIndex).setPreferredWidth(180);
}
 
源代码11 项目: pcgen   文件: EquipmentModels.java
@Override
public void actionPerformed(ActionEvent e)
{
	EquipmentSetFacade equipSet = character.getEquipmentSetRef().get();
	List<EquipNode> paths = getSelectedEquipmentSetNodes();
	if (!paths.isEmpty())
	{
		Object[][] data = new Object[paths.size()][3];
		for (int i = 0; i < paths.size(); i++)
		{
			EquipNode path = paths.get(i);
			data[i][0] = path.getEquipment();
			data[i][1] = equipSet.getQuantity(path);
		}
		Object[] columns = {LanguageBundle.getString("in_equipItem"), //$NON-NLS-1$
			LanguageBundle.getString("in_equipQuantityAbbrev"), //$NON-NLS-1$
		};
		DefaultTableModel tableModel = new DefaultTableModel(data, columns)
		{

			@Override
			public Class<?> getColumnClass(int columnIndex)
			{
				if (columnIndex == 1)
				{
					return Integer.class;
				}
				return Object.class;
			}

			@Override
			public boolean isCellEditable(int row, int column)
			{
				return column != 0;
			}

		};
		JTable table = new JTable(tableModel);
		table.setFocusable(false);
		table.setCellSelectionEnabled(false);
		table.setDefaultRenderer(Integer.class, new TableCellUtilities.SpinnerRenderer());
		table.setDefaultEditor(Integer.class, new SpinnerEditor(equipSet.getEquippedItems()));
		table.setRowHeight(22);
		table.getColumnModel().getColumn(0).setPreferredWidth(140);
		table.getColumnModel().getColumn(1).setPreferredWidth(50);
		table.setPreferredScrollableViewportSize(table.getPreferredSize());
		JTableHeader header = table.getTableHeader();
		header.setReorderingAllowed(false);
		JScrollPane pane = EquipmentModels.prepareScrollPane(table);
		JPanel panel = new JPanel(new BorderLayout());
		JLabel help = new JLabel(LanguageBundle.getString("in_equipSelectUnequipQty")); //$NON-NLS-1$
		panel.add(help, BorderLayout.NORTH);
		panel.add(pane, BorderLayout.CENTER);
		int res = JOptionPane.showConfirmDialog(JOptionPane.getFrameForComponent(equipmentTable), panel,
			LanguageBundle.getString("in_equipUnequipSel"), //$NON-NLS-1$
			JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

		if (res == JOptionPane.OK_OPTION)
		{
			for (int i = 0; i < paths.size(); i++)
			{
				equipSet.removeEquipment(paths.get(i), (Integer) tableModel.getValueAt(i, 1));
			}
		}
	}
}
 
源代码12 项目: pcgen   文件: TableUtils.java
public static JScrollPane createRadioBoxSelectionPane(JTable table, JTable rowheaderTable)
{
	rowheaderTable.setDefaultEditor(Boolean.class, new TableCellUtilities.RadioButtonEditor());
	return createToggleButtonSelectionPane(table, rowheaderTable, new JRadioButton());
}
 
源代码13 项目: mzmine2   文件: IsotopePatternPreviewDialog.java
@Override
protected void addDialogComponents() {
  super.addDialogComponents();

  pFormula = parameterSet.getParameter(IsotopePatternPreviewParameters.formula);
  pMinIntensity = parameterSet.getParameter(IsotopePatternPreviewParameters.minIntensity);
  pMergeWidth = parameterSet.getParameter(IsotopePatternPreviewParameters.mergeWidth);
  pCharge = parameterSet.getParameter(IsotopePatternPreviewParameters.charge);

  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

  cmpMinIntensity =
      (PercentComponent) getComponentForParameter(IsotopePatternPreviewParameters.minIntensity);
  cmpMergeWidth =
      (DoubleComponent) getComponentForParameter(IsotopePatternPreviewParameters.mergeWidth);
  cmpCharge = (IntegerComponent) getComponentForParameter(IsotopePatternPreviewParameters.charge);
  cmpFormula =
      (StringComponent) getComponentForParameter(IsotopePatternPreviewParameters.formula);

  // panels
  newMainPanel = new JPanel(new BorderLayout());
  pnText = new JScrollPane();
  pnlChart = new EChartPanel(chart);
  pnSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, pnlChart, pnText);
  table = new JTable();
  pnlParameters = new JPanel(new FlowLayout());
  pnlControl = new JPanel(new BorderLayout());

  pnText.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  pnText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

  pnText.setMinimumSize(new Dimension(350, 300));
  pnlChart.setMinimumSize(new Dimension(350, 200));
  pnlChart.setPreferredSize( // TODO: can you do this cleaner?
      new Dimension((int) (screenSize.getWidth() / 3), (int) (screenSize.getHeight() / 3)));
  table.setMinimumSize(new Dimension(350, 300));
  table.setDefaultEditor(Object.class, null);

  // controls
  ttGen = new SpectraToolTipGenerator();
  theme = new EIsotopePatternChartTheme();
  theme.initialize();

  // reorganize
  getContentPane().remove(mainPanel);
  organizeParameterPanel();
  pnlControl.add(pnlParameters, BorderLayout.CENTER);
  pnlControl.add(pnlButtons, BorderLayout.SOUTH);
  newMainPanel.add(pnSplit, BorderLayout.CENTER);
  newMainPanel.add(pnlControl, BorderLayout.SOUTH);
  getContentPane().add(newMainPanel);
  pnlButtons.remove(super.btnCancel);

  chart = ChartFactory.createXYBarChart("Isotope pattern preview", "m/z", false, "Abundance",
      new XYSeriesCollection(new XYSeries("")));
  pnlChart.setChart(chart);
  pnText.setViewportView(table);

  updateMinimumSize();
  pack();
}
 
源代码14 项目: pcgen   文件: EquipmentModels.java
@Override
public void actionPerformed(ActionEvent e)
{
	EquipmentSetFacade equipSet = character.getEquipmentSetRef().get();
	List<EquipNode> paths = getSelectedEquipmentSetNodes();
	if (!paths.isEmpty())
	{
		Object[][] data = new Object[paths.size()][3];
		for (int i = 0; i < paths.size(); i++)
		{
			EquipNode path = paths.get(i);
			data[i][0] = path.getEquipment();
			data[i][1] = equipSet.getQuantity(path);
		}
		Object[] columns = {LanguageBundle.getString("in_equipItem"), //$NON-NLS-1$
			LanguageBundle.getString("in_equipQuantityAbbrev"), //$NON-NLS-1$
		};
		DefaultTableModel tableModel = new DefaultTableModel(data, columns)
		{

			@Override
			public Class<?> getColumnClass(int columnIndex)
			{
				if (columnIndex == 1)
				{
					return Integer.class;
				}
				return Object.class;
			}

			@Override
			public boolean isCellEditable(int row, int column)
			{
				return column != 0;
			}

		};
		JTable table = new JTable(tableModel);
		table.setFocusable(false);
		table.setCellSelectionEnabled(false);
		table.setDefaultRenderer(Integer.class, new TableCellUtilities.SpinnerRenderer());
		table.setDefaultEditor(Integer.class, new SpinnerEditor(equipSet.getEquippedItems()));
		table.setRowHeight(22);
		table.getColumnModel().getColumn(0).setPreferredWidth(140);
		table.getColumnModel().getColumn(1).setPreferredWidth(50);
		table.setPreferredScrollableViewportSize(table.getPreferredSize());
		JTableHeader header = table.getTableHeader();
		header.setReorderingAllowed(false);
		JScrollPane pane = EquipmentModels.prepareScrollPane(table);
		JPanel panel = new JPanel(new BorderLayout());
		JLabel help = new JLabel(LanguageBundle.getString("in_equipSelectUnequipQty")); //$NON-NLS-1$
		panel.add(help, BorderLayout.NORTH);
		panel.add(pane, BorderLayout.CENTER);
		int res = JOptionPane.showConfirmDialog(JOptionPane.getFrameForComponent(equipmentTable), panel,
			LanguageBundle.getString("in_equipUnequipSel"), //$NON-NLS-1$
			JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

		if (res == JOptionPane.OK_OPTION)
		{
			for (int i = 0; i < paths.size(); i++)
			{
				equipSet.removeEquipment(paths.get(i), (Integer) tableModel.getValueAt(i, 1));
			}
		}
	}
}
 
源代码15 项目: pcgen   文件: TableUtils.java
public static JScrollPane createRadioBoxSelectionPane(JTable table, JTable rowheaderTable)
{
	rowheaderTable.setDefaultEditor(Boolean.class, new TableCellUtilities.RadioButtonEditor());
	return createToggleButtonSelectionPane(table, rowheaderTable, new JRadioButton());
}
 
public static void main(String[] args) {

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }

        DefaultTableModel dm = new DefaultTableModel(new Object[][]{
                {"C1", Color.RED},
                {"C2", Color.GREEN},
                {"C3", Color.BLUE}},
                                                     new String[]{"Name", "Color"}) {


            @Override
            public Class<?> getColumnClass(int columnIndex) {
                return columnIndex == 0 ? String.class : Color.class;
            }
        };

        JTable table = new JTable(dm);
        ColorTableCellEditor editor = new ColorTableCellEditor();
        ColorTableCellRenderer renderer = new ColorTableCellRenderer();
        table.setDefaultEditor(Color.class, editor);
        table.setDefaultRenderer(Color.class, renderer);
        table.getModel().addTableModelListener(e -> System.out.println("e = " + e));

        ColorComboBox colorComboBox1 = new ColorComboBox(Color.YELLOW);
        ColorComboBox colorComboBox2 = new ColorComboBox(Color.GREEN);
        colorComboBox2.setColorChooserPanelFactory(CustomColorChooserPanel::new);

        JFrame frame = new JFrame("Color Selection Test");
        frame.setLocation(200, 100);
        frame.add(colorComboBox1, BorderLayout.NORTH);
        frame.add(new JScrollPane(table), BorderLayout.CENTER);
        frame.add(colorComboBox2, BorderLayout.SOUTH);
        frame.pack();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
 
 方法所在类
 同类方法