Java Code Examples for javax.swing.JTree#setRowHeight()

The following examples show how to use javax.swing.JTree#setRowHeight() . 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: MTGPluginTreeCellRenderer.java    From MtgDesktopCompanion with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf,int row, boolean hasFocus) {
	JLabel lab = new JLabel();
	tree.setRowHeight(MTGConstants.TREE_ROW_HEIGHT);
	lab.setBackground(tree.getBackground());
	lab.setForeground(tree.getForeground());
	if(value instanceof MTGPlugin)
	{
	   lab.setFont(lab.getFont().deriveFont(Font.BOLD));
	   lab.setText(value.toString());
	   lab.setIcon(((MTGPlugin)value).getIcon());
		
	}else if (value instanceof Entry)
	{
		lab.setIcon(MTGConstants.ICON_MANA_INCOLOR);
		lab.setText(((Entry)value).getKey().toString());
	}
	return lab;
}
 
Example 2
Source File: SLDTree.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Creates the ui. */
private void createUI() {
    setBorder(new LineBorder(new Color(0, 0, 0)));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    JPanel panelSymbolMarkerTree = new JPanel();
    add(panelSymbolMarkerTree);

    // CHECKSTYLE:OFF
    JScrollPane scrollpane = new JScrollPane();
    // CHECKSTYLE:ON

    rootNode = new DefaultMutableTreeNode("SLD");
    treeModel = new DefaultTreeModel(rootNode);
    symbolTree = new JTree(treeModel);
    symbolTree.setEditable(true);
    symbolTree.setBorder(new LineBorder(Color.black));
    ComponentCellRenderer cellRenderer =
            new ComponentCellRenderer(symbolTree.getCellRenderer());
    symbolTree.setCellRenderer(cellRenderer);
    symbolTree.setCellEditor(new CheckBoxNodeEditor(symbolTree, cellRenderer, this));
    symbolTree.setEditable(true);
    symbolTree.setRowHeight(0);

    // Listen for when the selection changes.
    symbolTree.addTreeSelectionListener(this);
    panelSymbolMarkerTree.setLayout(new BorderLayout(0, 0));

    scrollpane.setViewportView(symbolTree);

    panelSymbolMarkerTree.add(scrollpane);

    // Add the tree tools if they were supplied
    if (treeTools != null) {
        treeTools.configure(this, symbolTree, treeModel, renderList);
        add(treeTools.getButtonPanel());
    } else {
        setPreferredSize(new Dimension(SLDTreeTools.getPanelWidth(), PANEL_HEIGHT));
    }
}
 
Example 3
Source File: DebugPanel.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
private void safeSetTreeModel(MyTreeTable tt, MyTreeTableModel tmodel) {
    List<List<String>> expanded = View.getExpandedNodes(tt.getTree());

    int[] selRows = tt.getSelectedRows();

    TreePath[] selPaths = new TreePath[selRows.length];
    for (int i = 0; i < selRows.length; i++) {
        selPaths[i] = tt.getTree().getPathForRow(selRows[i]);
    }
    tt.setTreeModel(tmodel);
    //tt.getTree().setRootVisible(false);

    View.expandTreeNodes(tt.getTree(), expanded);
    for (int i = 0; i < selRows.length; i++) {
        selRows[i] = tt.getTree().getRowForPath(selPaths[i]);
        if (selRows[i] == -1) {
            continue;
        }
        if (i == 0) {
            tt.setRowSelectionInterval(selRows[i], selRows[i]);
        } else {
            tt.addRowSelectionInterval(selRows[i], selRows[i]);
        }
    }

    int ROW_HEIGHT = new JLabel("A").getPreferredSize().height;

    JTree tree = tt.getTree();
    tree.setRowHeight(ROW_HEIGHT);
    for (int i = 0; i < tt.getRowCount(); i++) {
        tt.setRowHeight(i, ROW_HEIGHT);
    }

}
 
Example 4
Source File: CheckTree.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new CheckBox tree.
 *
 * @param rootNode Node that is the root of this tree.
 */
public CheckTree(CheckNode rootNode) {
    tree = new JTree(rootNode);
    tree.setCellRenderer(new CheckRenderer());
    tree.setRowHeight(18);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setToggleClickCount(1000);
    tree.putClientProperty("JTree.lineStyle", "Angled");
    tree.addMouseListener(new NodeSelectionListener(tree));

    setLayout(new BorderLayout());
    add(tree, BorderLayout.CENTER);
}
 
Example 5
Source File: CorefEditor.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * This method intiates the GUI for co-reference editor
 */
@Override
protected void initGUI() {

  //get a pointer to the textual view used for highlights
  Iterator<DocumentView> centralViewsIter = owner.getCentralViews().iterator();
  while (textView == null && centralViewsIter.hasNext()) {
    DocumentView aView = centralViewsIter.next();
    if (aView instanceof TextualDocumentView)
      textView = (TextualDocumentView) aView;
  }
  textPane = (JTextArea) ( (JScrollPane) textView.getGUI()).getViewport().
             getView();
  highlighter = textPane.getHighlighter();
  chainToolTipAction = new ChainToolTipAction();
  chainToolTipTimer = new javax.swing.Timer(500, chainToolTipAction);
  chainToolTipTimer.setRepeats(false);
  newCorefAction = new NewCorefAction();
  newCorefActionTimer = new javax.swing.Timer(500, newCorefAction);
  newCorefActionTimer.setRepeats(false);

  colorGenerator = new ColorGenerator();

  // main Panel
  mainPanel = new JPanel();
  mainPanel.setLayout(new BorderLayout());

  // topPanel
  topPanel = new JPanel();
  topPanel.setLayout(new BorderLayout());

  // subPanel
  subPanel = new JPanel();
  subPanel.setLayout(new FlowLayout(FlowLayout.LEFT));

  // showAnnotations Button
  showAnnotations = new JToggleButton("Show");
  showAnnotations.addActionListener(this);

  // annotSets
  annotSets = new JComboBox<String>();
  annotSets.addActionListener(this);

  // get all the annotationSets
  Map<String,AnnotationSet> annotSetsMap = document.getNamedAnnotationSets();
  annotSetsModel = new DefaultComboBoxModel<String>();
  if (annotSetsMap != null) {
    String [] array = annotSetsMap.keySet().toArray(new String[annotSetsMap.keySet().size()]);
    for(int i=0;i<array.length;i++) {
      annotSetsMap.get(array[i]).addAnnotationSetListener(this);
    }
    annotSetsModel = new DefaultComboBoxModel<String>(array);
  }
  document.getAnnotations().addAnnotationSetListener(this);
  annotSetsModel.insertElementAt(DEFAULT_ANNOTSET_NAME, 0);
  annotSets.setModel(annotSetsModel);

  // annotTypes
  annotTypesModel = new DefaultComboBoxModel<String>();
  annotTypes = new JComboBox<String>(annotTypesModel);
  annotTypes.addActionListener(this);
  subPanel.add(new JLabel("Sets : "));
  subPanel.add(annotSets);
  JPanel tempPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
  tempPanel.add(new JLabel("Types : "));
  tempPanel.add(annotTypes);
  tempPanel.add(showAnnotations);
  // intialises the Data
  initData();

  // and creating the tree
  corefTree = new JTree(rootNode);
  corefTree.putClientProperty("JTree.lineStyle", "None");
  corefTree.setRowHeight(corefTree.getRowHeight() * 2);
  corefTree.setLargeModel(true);
  corefTree.setAutoscrolls(true);

  //corefTree.setRootVisible(false);
  //corefTree.setShowsRootHandles(false);
  corefTree.addMouseListener(new CorefTreeMouseListener());
  corefTree.setCellRenderer(new CorefTreeCellRenderer());

  mainPanel.add(topPanel, BorderLayout.NORTH);
  mainPanel.add(new JScrollPane(corefTree), BorderLayout.CENTER);
  topPanel.add(subPanel, BorderLayout.CENTER);
  topPanel.add(tempPanel, BorderLayout.SOUTH);

  // get the highlighter
  textPaneMouseListener = new TextPaneMouseListener();
  annotSets.setSelectedIndex(0);

  // finally show the tree
  //annotSetSelectionChanged();

  document.addDocumentListener(this);
  document.getFeatures().addFeatureMapListener(this);
}
 
Example 6
Source File: DThrowableDetail.java    From portecle with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initialize the dialog's GUI components.
 */
private void initComponents()
{
	// Buttons
	JPanel jpButtons = new JPanel(new FlowLayout(FlowLayout.CENTER));

	JButton jbOK = getOkButton(true);
	jpButtons.add(jbOK);

	JButton jbCopy = new JButton(RB.getString("DThrowableDetail.jbCopy.text"));
	jbCopy.setMnemonic(RB.getString("DThrowableDetail.jbCopy.mnemonic").charAt(0));
	jbCopy.setToolTipText(RB.getString("DThrowableDetail.jbCopy.tooltip"));
	jbCopy.addActionListener(new ActionListener()
	{
		@Override
		public void actionPerformed(ActionEvent evt)
		{
			copyPressed();
		}
	});
	jpButtons.add(jbCopy);

	JPanel jpThrowable = new JPanel(new BorderLayout());
	jpThrowable.setBorder(new EmptyBorder(5, 5, 5, 5));

	// Load tree with info on throwable's stack trace
	JTree jtrThrowable = new JTree(createThrowableNodes());
	// Top accommodate node icons with spare space (they are 16 pixels tall)
	jtrThrowable.setRowHeight(18);
	jtrThrowable.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	// Allow tool tips in tree
	ToolTipManager.sharedInstance().registerComponent(jtrThrowable);
	// Custom tree node renderer
	jtrThrowable.setCellRenderer(new ThrowableTreeCellRend());

	// Expand all nodes in tree
	/*
	 * ...then again, not. Too much scary detail. TreeNode topNode = (TreeNode)jtrThrowable.getModel().getRoot();
	 * expandTree(jtrThrowable, new TreePath(topNode));
	 */

	JScrollPane jspThrowable = new JScrollPane(jtrThrowable, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
	    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
	jspThrowable.setPreferredSize(new Dimension(500, 250));
	jpThrowable.add(jspThrowable, BorderLayout.CENTER);

	getContentPane().add(jpThrowable, BorderLayout.CENTER);
	getContentPane().add(jpButtons, BorderLayout.SOUTH);

	setTitle(RB.getString("DThrowableDetail.Title"));

	getRootPane().setDefaultButton(jbOK);

	initDialog();

	setResizable(true);
	jbOK.requestFocusInWindow();
}
 
Example 7
Source File: DProviderInfo.java    From portecle with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initialize the dialog's GUI components.
 */
private void initComponents()
{
	// Buttons
	JPanel jpButtons = new JPanel(new FlowLayout(FlowLayout.CENTER));

	JButton jbOK = getOkButton(true);
	jpButtons.add(jbOK);

	JButton jbCopy = new JButton(RB.getString("DProviderInfo.jbCopy.text"));
	jbCopy.setMnemonic(RB.getString("DProviderInfo.jbCopy.mnemonic").charAt(0));
	jbCopy.setToolTipText(RB.getString("DProviderInfo.jbCopy.tooltip"));
	jbCopy.addActionListener(new ActionListener()
	{
		@Override
		public void actionPerformed(ActionEvent evt)
		{
			copyPressed();
		}
	});

	jpButtons.add(jbCopy);

	JPanel jpProviders = new JPanel(new BorderLayout());
	jpProviders.setBorder(new EmptyBorder(5, 5, 5, 5));

	// Load tree with info on loaded security providers
	JTree jtrProviders = new JTree(createProviderNodes());
	// Top accommodate node icons with spare space (they are 16 pixels tall)
	jtrProviders.setRowHeight(18);
	jtrProviders.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	// Allow tool tips in tree
	ToolTipManager.sharedInstance().registerComponent(jtrProviders);
	// Custom tree node renderer
	jtrProviders.setCellRenderer(new ProviderTreeCellRend());

	JScrollPane jspProviders = new JScrollPane(jtrProviders, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
	    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
	jspProviders.setPreferredSize(new Dimension(350, 200));
	jpProviders.add(jspProviders, BorderLayout.CENTER);

	getContentPane().add(jpProviders, BorderLayout.CENTER);
	getContentPane().add(jpButtons, BorderLayout.SOUTH);

	setTitle(RB.getString("DProviderInfo.Title"));

	getRootPane().setDefaultButton(jbOK);

	initDialog();

	setResizable(true);
	jbOK.requestFocusInWindow();
}