Java Code Examples for javax.swing.JTable#setCellSelectionEnabled()

The following examples show how to use javax.swing.JTable#setCellSelectionEnabled() . 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: ClassLevelTableModel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void initializeTable(JTable classLevelTable)
{
	JTableHeader tableHeader = classLevelTable.getTableHeader();
	tableHeader.setResizingAllowed(false);
	tableHeader.setReorderingAllowed(false);
	TableColumnModel columnModel = new DefaultTableColumnModel();
	TableCellRenderer headerRenderer = tableHeader.getDefaultRenderer();
	columnModel.addColumn(Utilities.createTableColumn(0, "Level", headerRenderer, false));
	columnModel.addColumn(Utilities.createTableColumn(1, "HP", headerRenderer, false));
	columnModel.addColumn(Utilities.createTableColumn(2, "Class (All Levels In Class)", headerRenderer, true));
	classLevelTable.setColumnModel(columnModel);
	classLevelTable.setAutoCreateColumnsFromModel(false);
	classLevelTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
	classLevelTable.setFocusable(false);
	classLevelTable.setCellSelectionEnabled(false);
	classLevelTable.setRowHeight(20);
}
 
Example 2
Source File: ClassLevelTableModel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void initializeTable(JTable classLevelTable)
{
	JTableHeader tableHeader = classLevelTable.getTableHeader();
	tableHeader.setResizingAllowed(false);
	tableHeader.setReorderingAllowed(false);
	TableColumnModel columnModel = new DefaultTableColumnModel();
	TableCellRenderer headerRenderer = tableHeader.getDefaultRenderer();
	columnModel.addColumn(Utilities.createTableColumn(0, "Level", headerRenderer, false));
	columnModel.addColumn(Utilities.createTableColumn(1, "HP", headerRenderer, false));
	columnModel.addColumn(Utilities.createTableColumn(2, "Class (All Levels In Class)", headerRenderer, true));
	classLevelTable.setColumnModel(columnModel);
	classLevelTable.setAutoCreateColumnsFromModel(false);
	classLevelTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
	classLevelTable.setFocusable(false);
	classLevelTable.setCellSelectionEnabled(false);
	classLevelTable.setRowHeight(20);
}
 
Example 3
Source File: PlannerWindow.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public void createTable() {

		// Create schedule table model
		if (unit instanceof Person)
			PlannerTableModel = new PlannerTableModel((Person) unit);
		else if (unit instanceof Robot)
			PlannerTableModel = new PlannerTableModel((Robot) unit);

		// Create attribute scroll panel
		JScrollPane scrollPanel = new JScrollPane();
		scrollPanel.setBorder(new MarsPanelBorder());

		// Create schedule table
		table = new JTable(PlannerTableModel);
		table.setPreferredScrollableViewportSize(new Dimension(225, 100));
		table.getColumnModel().getColumn(0).setPreferredWidth(25);
		table.getColumnModel().getColumn(1).setPreferredWidth(150);
		table.setCellSelectionEnabled(false);
		// table.setDefaultRenderer(Integer.class, new NumberCellRenderer());
		scrollPanel.setViewportView(table);

		// 2015-06-08 Added sorting
		table.setAutoCreateRowSorter(true);
	    //if (!MainScene.OS.equals("linux")) {
	    //	table.getTableHeader().setDefaultRenderer(new MultisortTableHeaderCellRenderer());
	    //}
		topPanel.add(scrollPanel, BorderLayout.CENTER);

		// 2015-06-08 Added setTableStyle()
		TableStyle.setTableStyle(table);

		update();
	}
 
Example 4
Source File: LanguageTableModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void initializeTable(JTable table)
{
	table.setCellSelectionEnabled(false);
	table.setRowSelectionAllowed(false);
	table.setColumnSelectionAllowed(false);
	table.setFocusable(false);
	table.setRowHeight(21);
	table.getTableHeader().setReorderingAllowed(false);
}
 
Example 5
Source File: TaskProgressTable.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor
 */
public TaskProgressTable() {

  super(new BorderLayout());

  add(new JLabel("Tasks in progress..."), BorderLayout.NORTH);

  TaskControllerImpl taskController = (TaskControllerImpl) MZmineCore.getTaskController();

  taskTable = new JTable(taskController.getTaskQueue());
  taskTable.setCellSelectionEnabled(false);
  taskTable.setColumnSelectionAllowed(false);
  taskTable.setRowSelectionAllowed(true);
  taskTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  taskTable.setDefaultRenderer(JComponent.class, new ComponentCellRenderer());
  taskTable.getTableHeader().setReorderingAllowed(false);

  JScrollPane jJobScroll = new JScrollPane(taskTable);
  add(jJobScroll, BorderLayout.CENTER);

  // Create popup menu and items
  popupMenu = new JPopupMenu();

  priorityMenu = new JMenu("Set priority...");
  highPriorityMenuItem = GUIUtils.addMenuItem(priorityMenu, "High", this);
  normalPriorityMenuItem = GUIUtils.addMenuItem(priorityMenu, "Normal", this);
  popupMenu.add(priorityMenu);

  cancelTaskMenuItem = GUIUtils.addMenuItem(popupMenu, "Cancel task", this);
  cancelAllMenuItem = GUIUtils.addMenuItem(popupMenu, "Cancel all tasks", this);

  // Addd popup menu to the task table
  taskTable.setComponentPopupMenu(popupMenu);

  // Set the width for first column (task description)
  taskTable.getColumnModel().getColumn(0).setPreferredWidth(350);

  jJobScroll.setPreferredSize(new Dimension(600, 120));

}
 
Example 6
Source File: LanguageTableModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void initializeTable(JTable table)
{
	table.setCellSelectionEnabled(false);
	table.setRowSelectionAllowed(false);
	table.setColumnSelectionAllowed(false);
	table.setFocusable(false);
	table.setRowHeight(21);
	table.getTableHeader().setReorderingAllowed(false);
}
 
Example 7
Source File: BuildingPanelMedicalCare.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor.
 * @param medical the medical care building this panel is for.
 * @param desktop The main desktop.
 */
public BuildingPanelMedicalCare(MedicalCare medical, MainDesktopPane desktop) {

	// Use BuildingFunctionPanel constructor
	super(medical.getBuilding(), desktop);

	// Initialize data members
	this.medical = medical;

	// Set panel layout
	setLayout(new BorderLayout());

	// Create label panel
	WebPanel labelPanel = new WebPanel(new GridLayout(3, 1, 0, 0));
	add(labelPanel, BorderLayout.NORTH);
	labelPanel.setOpaque(false);
	labelPanel.setBackground(new Color(0,0,0,128));

	// Create medical care label
	// 2014-11-21 Changed font type, size and color and label text
	// 2014-11-21 Added internationalization for labels
	WebLabel medicalCareLabel = new WebLabel(Msg.getString("BuildingPanelMedicalCare.title"), WebLabel.CENTER);
	medicalCareLabel.setFont(new Font("Serif", Font.BOLD, 16));
	//medicalCareLabel.setForeground(new Color(102, 51, 0)); // dark brown
	labelPanel.add(medicalCareLabel);

	// Create sick bed label
	WebLabel sickBedLabel = new WebLabel(Msg.getString("BuildingPanelMedicalCare.numberOfsickBeds",
			medical.getSickBedNum()), WebLabel.CENTER);
	labelPanel.add(sickBedLabel);

	// Create physician label
	physicianCache = medical.getPhysicianNum();
	physicianLabel = new WebLabel(Msg.getString("BuildingPanelMedicalCare.numberOfPhysicians",
			physicianCache), WebLabel.CENTER);
	labelPanel.add(physicianLabel);

	// Create scroll panel for medical table
	WebScrollPane scrollPanel = new WebScrollPane();
	scrollPanel.setPreferredSize(new Dimension(160, 80));
	add(scrollPanel, BorderLayout.CENTER);
    scrollPanel.getViewport().setOpaque(false);
    scrollPanel.getViewport().setBackground(new Color(0, 0, 0, 0));
    scrollPanel.setOpaque(false);
    scrollPanel.setBackground(new Color(0, 0, 0, 0));
       //scrollPanel.setBorder( BorderFactory.createLineBorder(Color.orange) );


	// Prepare medical table model
	medicalTableModel = new MedicalTableModel(medical);

	// Prepare medical table
	JTable medicalTable = new ZebraJTable(medicalTableModel);
	medicalTable.setCellSelectionEnabled(false);
	scrollPanel.setViewportView(medicalTable);
}
 
Example 8
Source File: SalvageTabPanel.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public void initializeUI() {
uiDone = true;

      Salvagable salvageItem = (Salvagable) unit;
      SalvageInfo salvageInfo = salvageItem.getSalvageInfo();
      
      // Create the salvage header panel.
      JPanel salvageHeaderPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 10));
      topContentPanel.add(salvageHeaderPanel);
      
      // Create the salvage header label.
      JLabel salvageHeaderLabel = new JLabel(unit.getName() + " has been salvaged.", JLabel.CENTER);
      salvageHeaderPanel.add(salvageHeaderLabel);
      
      // Create the salvage info panel.
      JPanel salvageInfoPanel = new JPanel(new BorderLayout(0, 0));
      topContentPanel.add(salvageInfoPanel);
      
      // Create the time panel.
      JPanel timePanel = new JPanel(new GridLayout(2, 1, 0, 0));
      salvageInfoPanel.add(timePanel, BorderLayout.NORTH);
      
      // Create the start time label.
      String startTimeString = salvageInfo.getStartTime().getDateTimeStamp();
      JLabel startTimeLabel = new JLabel("Start Time: " + startTimeString, JLabel.LEFT);
      timePanel.add(startTimeLabel);
      
      // Create the finish time label.
      MarsClock finishTime = salvageInfo.getFinishTime();
      finishTimeString = "";
      if (finishTime != null) finishTimeString = finishTime.getDateTimeStamp();
      finishTimeLabel = new JLabel("Finish Time: " + finishTimeString, JLabel.LEFT);
      timePanel.add(finishTimeLabel);

      // Create the settlement panel.
      JPanel settlementPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
      salvageInfoPanel.add(settlementPanel);
      
      // Create the settlement label.
      JLabel settlementLabel = new JLabel("Settlement: ");
      settlementPanel.add(settlementLabel);
      
      // Create the settlement button.
      JButton settlementButton = new JButton(salvageInfo.getSettlement().getName());
      settlementButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent event) {
              SalvageInfo info = ((Salvagable) getUnit()).getSalvageInfo();
              getDesktop().openUnitWindow(info.getSettlement(), false);
          }
      });
      settlementPanel.add(settlementButton);
      
      // Create the parts panel.
      JPanel partsPanel = new JPanel(new BorderLayout(0, 10));
      partsPanel.setBorder(new MarsPanelBorder());
      topContentPanel.add(partsPanel);
      
      // Create the parts label.
      JLabel partsLabel = new JLabel("Salvaged Parts", JLabel.CENTER);
      partsPanel.add(partsLabel, BorderLayout.NORTH);
      
      // Create the parts table panel.
      JScrollPane partsTablePanel = new JScrollPane();
      partsPanel.add(partsTablePanel, BorderLayout.CENTER);
      
      // Create the parts table.
      partTableModel = new PartTableModel(salvageInfo);
      JTable partsTable = new JTable(partTableModel);
      partsTable.setPreferredScrollableViewportSize(new Dimension(150, 75));
      partsTable.getColumnModel().getColumn(0).setPreferredWidth(100);
      partsTable.getColumnModel().getColumn(1).setPreferredWidth(50);
      partsTable.setCellSelectionEnabled(false);
      partsTable.setDefaultRenderer(Double.class, new NumberCellRenderer(1));
      partsTablePanel.setViewportView(partsTable);
  }
 
Example 9
Source File: OngoingStudyListPanel.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor.
 * @param scienceWindow the science window.
 */
public OngoingStudyListPanel(ScienceWindow scienceWindow) {
	// Use JPanel constructor.
	super();

	this.scienceWindow = scienceWindow;

	setLayout(new BorderLayout());

	// Create title label.
	JLabel titleLabel = new JLabel(Msg.getString("OngoingStudyListPanel.ongoingScientificStudies"), JLabel.CENTER); //$NON-NLS-1$
	add(titleLabel, BorderLayout.NORTH);

	// Create list scroll pane.
	listScrollPane = new JScrollPane();
	listScrollPane.setBorder(new MarsPanelBorder());
	listScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
	add(listScrollPane, BorderLayout.CENTER);

	// Create study table model.
	studyTableModel = new StudyTableModel();

	// Create study table.
	studyTable = new JTable(studyTableModel);
	studyTable.setPreferredScrollableViewportSize(new Dimension(500, 200));
	studyTable.setCellSelectionEnabled(false);
	studyTable.setRowSelectionAllowed(true);
	studyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	studyTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
		public void valueChanged(ListSelectionEvent event) {
			if (event.getValueIsAdjusting()) {
				int row = studyTable.getSelectedRow();
				if (row >= 0) {
					ScientificStudy selectedStudy = studyTableModel.getStudy(row);
					if (selectedStudy != null) setSelectedScientificStudy(selectedStudy);
				}
			}
		}
	});
	studyTable.getColumnModel().getColumn(0).setPreferredWidth(40);
	studyTable.getColumnModel().getColumn(1).setPreferredWidth(7);
	studyTable.getColumnModel().getColumn(2).setPreferredWidth(80);
	studyTable.getColumnModel().getColumn(3).setPreferredWidth(80);
	studyTable.getColumnModel().getColumn(3).setPreferredWidth(80);
	
	studyTable.setAutoCreateRowSorter(true);
	
	TableStyle.setTableStyle(studyTable);
	
	listScrollPane.setViewportView(studyTable);
}
 
Example 10
Source File: FinishedStudyListPanel.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor
 * 
 * @param scienceWindow the science window.
 */
FinishedStudyListPanel(ScienceWindow scienceWindow) {
	// Use JPanel constructor.
	super();

	this.scienceWindow = scienceWindow;

	setLayout(new BorderLayout());

	JLabel titleLabel = new JLabel(Msg.getString("FinishedStudyListPanel.finishedScientificStudies"), //$NON-NLS-1$
			JLabel.CENTER);
	add(titleLabel, BorderLayout.NORTH);

	// Create list scroll pane.
	listScrollPane = new JScrollPane();
	listScrollPane.setBorder(new MarsPanelBorder());
	listScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
	add(listScrollPane, BorderLayout.CENTER);

	// Create study table model.
	studyTableModel = new StudyTableModel();

	// Create study table.
	studyTable = new JTable(studyTableModel);
	studyTable.setPreferredScrollableViewportSize(new Dimension(500, 200));
	studyTable.setCellSelectionEnabled(false);
	studyTable.setRowSelectionAllowed(true);
	studyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	studyTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
		public void valueChanged(ListSelectionEvent event) {
			if (event.getValueIsAdjusting()) {
				int row = studyTable.getSelectedRow();
				if (row >= 0) {
					ScientificStudy selectedStudy = studyTableModel.getStudy(row);
					if (selectedStudy != null)
						setSelectedScientificStudy(selectedStudy);
				}
			}
		}
	});
	studyTable.getColumnModel().getColumn(0).setPreferredWidth(40);
	studyTable.getColumnModel().getColumn(1).setPreferredWidth(7);
	studyTable.getColumnModel().getColumn(2).setPreferredWidth(80);
	studyTable.getColumnModel().getColumn(3).setPreferredWidth(80);
	studyTable.getColumnModel().getColumn(3).setPreferredWidth(80);
	
	studyTable.setAutoCreateRowSorter(true);

	TableStyle.setTableStyle(studyTable);

	listScrollPane.setViewportView(studyTable);
}
 
Example 11
Source File: EquipmentModels.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
@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));
			}
		}
	}
}
 
Example 12
Source File: StatTableModel.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void initializeTable(JTable statsTable)
{
	JTableHeader tableHeader = statsTable.getTableHeader();
	tableHeader.setResizingAllowed(false);
	tableHeader.setReorderingAllowed(false);

	statsTable.setAutoCreateColumnsFromModel(false);
	DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
	{
		TableColumn column =
				Utilities.createTableColumn(ABILITY_NAME, "Ability", new AbilityHeaderCellRenderer(), true);
		column.setIdentifier(ABILITY_COLUMN_ID);
		columnModel.addColumn(column);

		String htmlText = "<html><div align=\"center\">Final<br>Score</div></html>";
		column = Utilities.createTableColumn(FINAL_ABILITY_SCORE, htmlText, new FixedHeaderCellRenderer(htmlText),
			false);
		column.setCellRenderer(new ValueRenderer());
		columnModel.addColumn(column);

		TableCellRenderer renderer = new ModRenderer();
		htmlText = "<html><div align=\"center\">Ability<br>Mod</div></html>";
		column = Utilities.createTableColumn(ABILITY_MOD, htmlText, new FixedHeaderCellRenderer(htmlText), false);
		column.setCellRenderer(renderer);
		columnModel.addColumn(column);

		htmlText = "<html><div align=\"center\">Editable<br>Score</div></html>";
		column = Utilities.createTableColumn(EDITABLE_SCORE, htmlText, new FixedHeaderCellRenderer(htmlText),
			false);
		column.setIdentifier(EDITABLE_COLUMN_ID);
		columnModel.addColumn(column);

		htmlText = "<html><div align=\"center\">Race<br>Adj</div></html>";
		column = Utilities.createTableColumn(RACE_ADJ, htmlText, new FixedHeaderCellRenderer(htmlText), false);
		column.setCellRenderer(renderer);
		columnModel.addColumn(column);

		htmlText = "<html><div align=\"center\">Misc<br>Adj</div></html>";
		column = Utilities.createTableColumn(MISC_ADJ, htmlText, new FixedHeaderCellRenderer(htmlText), false);
		column.setCellRenderer(renderer);
		columnModel.addColumn(column);
	}
	statsTable.setColumnModel(columnModel);
	statsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	statsTable.setShowVerticalLines(false);
	statsTable.setCellSelectionEnabled(false);
	statsTable.setFocusable(false);
	// XXX this should be calculated relative to font size and the size of a jspinner
	statsTable.setRowHeight(27);
	statsTable.setOpaque(false);
	tableHeader.setFont(FontManipulation.title(statsTable.getFont()));
	FontManipulation.large(statsTable);
}
 
Example 13
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();
}
 
Example 14
Source File: EquipmentModels.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
@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));
			}
		}
	}
}
 
Example 15
Source File: StatTableModel.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void initializeTable(JTable statsTable)
{
	JTableHeader tableHeader = statsTable.getTableHeader();
	tableHeader.setResizingAllowed(false);
	tableHeader.setReorderingAllowed(false);

	statsTable.setAutoCreateColumnsFromModel(false);
	DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
	{
		TableColumn column =
				Utilities.createTableColumn(ABILITY_NAME, "Ability", new AbilityHeaderCellRenderer(), true);
		column.setIdentifier(ABILITY_COLUMN_ID);
		columnModel.addColumn(column);

		String htmlText = "<html><div align=\"center\">Final<br>Score</div></html>";
		column = Utilities.createTableColumn(FINAL_ABILITY_SCORE, htmlText, new FixedHeaderCellRenderer(htmlText),
			false);
		column.setCellRenderer(new ValueRenderer());
		columnModel.addColumn(column);

		TableCellRenderer renderer = new ModRenderer();
		htmlText = "<html><div align=\"center\">Ability<br>Mod</div></html>";
		column = Utilities.createTableColumn(ABILITY_MOD, htmlText, new FixedHeaderCellRenderer(htmlText), false);
		column.setCellRenderer(renderer);
		columnModel.addColumn(column);

		htmlText = "<html><div align=\"center\">Editable<br>Score</div></html>";
		column = Utilities.createTableColumn(EDITABLE_SCORE, htmlText, new FixedHeaderCellRenderer(htmlText),
			false);
		column.setIdentifier(EDITABLE_COLUMN_ID);
		columnModel.addColumn(column);

		htmlText = "<html><div align=\"center\">Race<br>Adj</div></html>";
		column = Utilities.createTableColumn(RACE_ADJ, htmlText, new FixedHeaderCellRenderer(htmlText), false);
		column.setCellRenderer(renderer);
		columnModel.addColumn(column);

		htmlText = "<html><div align=\"center\">Misc<br>Adj</div></html>";
		column = Utilities.createTableColumn(MISC_ADJ, htmlText, new FixedHeaderCellRenderer(htmlText), false);
		column.setCellRenderer(renderer);
		columnModel.addColumn(column);
	}
	statsTable.setColumnModel(columnModel);
	statsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	statsTable.setShowVerticalLines(false);
	statsTable.setCellSelectionEnabled(false);
	statsTable.setFocusable(false);
	// XXX this should be calculated relative to font size and the size of a jspinner
	statsTable.setRowHeight(27);
	statsTable.setOpaque(false);
	tableHeader.setFont(FontManipulation.title(statsTable.getFont()));
	FontManipulation.large(statsTable);
}