JTree Branch Icon Rendering

Nov 12, 2014

I have a problem I must solve and could not find an answer after a couple weeks of research, so here I am. I have created a custom Table Cell Renderer than extends DefaultTreeCellRenderer. The mission of this renderer is to set the branch icons depending on conditional statements. There are 3 conditions, and each one should render a different icon. These conditions must be tested against all branches in the tree. This means that using something like setOpenIcon() and setClosedIcon() will not work since it seems as though these methods set all branches to a specific icon (I could be wrong about that though). Below is the code for my custom. I made comments so it is easier to understand what I want to happen and what is not happening.

/**Custom Cell Render that will set the icons for the tree branches and the leafs*/
private TreeIconCellRenderer extends DefaultTreeCellRenderer{
public Component.getTreeCellRendererComponent(JTree tree, Object value,boolean selected,boolean expanded, boolean leaf, boolean row, boolean hasFocus){
//Get defaults in case there is no need to renderer

[Code] ...

What I really need to know is why the renderer is not differentiating between the leaves and branches. The logging statements I have added confirm that the branch block of code does not execute.

View Replies


ADVERTISEMENT

File Filter In JTree

Apr 4, 2014

My goal is to display file that have extension *.java,I was wrote this swing in netbeans,

Java Code:
private static class FileSystemModel implements TreeModel {
private File root;
private Vector listeners = new Vector();
public FileSystemModel(File rootDirectory) {
root = rootDirectory;

[code]....

View Replies View Related

Swing/AWT/SWT :: Custom Jtree Renderer

Nov 2, 2014

I would like to ask about JTree custom renderer. What could be wrong with this. Here's the deal:

I have a Jtree which suppose to view the structure of given folder, so far so good its working. But my problem is that i dont want it to show the full path as name, only folder name and file name. I wrote a custom JTree renderer in hope that this will solve my problem but it didn't.

Here is my custom Jtree renderer:

private static class MyTreeCellRenderer extends DefaultTreeCellRenderer {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if( value instanceof DefaultMutableTreeNode){

[Code] .....

and here is where I am trying to implement it:

tree.setCellRenderer( new MyTreeCellRenderer());

View Replies View Related

Swing/AWT/SWT :: Manually Select A Node In JTree?

Oct 24, 2014

I have problem with manually (through my java code) selecting items in a JTree. I did Google the problem and found solutions here :

[URL]

This code worked for me only partially. Once I tried selecting deeper nested nodes, I ran into problems. Since my production code is very cluttered I built an example and reproduced my exact problem in it.

DummyView.java
package de.fortis.tcws.client.controller;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

[code].....

The important method is 'manualSelect(String[])'.

It streps through the tree by comparing user objects and finds the target node. Then it calls 'navigateToNode()' which uses the solution discussed in the links above.

This method behaves incosistently:

If you call it with an empty array it will correctly select the root node. The righthand pane shows the text of the selected node. = correct

If you call it with target node 1 it will correctly select node 1. The righthand pane shows the text of the selected node. = correct

If you call it with target node 1.1 it will select node 1.1 but for some reason it is not displayed as marked (no background). The righthand pane shows the text of the selected node. = only partly correct

If you call it with target node A it will run into an exception. Debugging reveals that the selection occurs correclty at first. You can also observe the righthand pane showing that 'A' was selected. But afterwards another TreeselectionEvent is occuring that has a NewLeadSelectionPath of null. I do not know where this second SelectionEvent is triggered from.

This code is run with Java 1.6.0_39 which is also what I will have to use in production.

View Replies View Related

Display More Information When Node Is Clicked In Jtree?

Aug 27, 2014

I'm new to java and I'm currently trying to make a program that uses a JTree that implements a properties file. I have the Keys set to the nodes but I want it so that when the node is clicked it will retrieve the keys value from the prop file.

I did have some code for this initially but I as it did not work at the time and was causing issues to my project I got rid of it. I have my code for the jtree,the listener and the prop file.

Tree

Java Code:

JPanel panel_1 = new JPanel();
panel_1.setBackground(Color.WHITE);
panel_1.setSize(new Dimension(22, 0));
scrollPane.setViewportView(panel_1);
Properties properties = new Properties();

[Code] ....

Java Code: add = Adds files changes in your working directory to your index. Example: git add .

rm = Removes files from your index and your working directory so they will not be tracked.

Example: git rm filename mh_sh_highlight_all('java');

Is there a way of doing this? Been trying for a while now but to no prevail. The image is what it currently looks like

View Replies View Related

Swing/AWT/SWT :: Build Code To Call Class As JTree?

Sep 28, 2014

I am trying to make a JTree. I have used this guide :[URL]

Now when I call my Class with

TreeMainMenu tree = new TreeMainMenu();
JScrollPane MainMenu = new JScrollPane(tree);

I get only the default JTree..

I need to understand how I should build my code to call the class as JTree.

This is my code:

public class TreeMainMenu extends JTree {
private DefaultMutableTreeNode top = new DefaultMutableTreeNode("TOP");
JTree tree;
public JTree TreeMainMenu() {
APNode();
tree = new JTree(top);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
return tree;

[code]....

View Replies View Related

Display Data Structure With JTree In A Swing Application

Aug 28, 2014

I have a tree-based data structure that looks somewhat like this:image1.png..Every tree always has a height of no more then 3, and each of these classes has a very specific use, generalization is not possible between them.Now, I want to display my data structure with a JTree in a Swing application. A JTree needs a TreeModel and so I created a custom TreeModel for my classes, it looks like this:

public class CustomTreeModel implements TreeModel {
private Root root;
public Object getRoot() {
return root;

[code]....

But then I would introduce this interface to my Model classes just for the purpose of writing the View. So my data model has to be altered to make the View work, this sounds completely against MVC to me and also like something I dont really like.On the other hand, the CustomTreeModel would be much simpler, easier to understand, easier to maintain and just in general more pleasing to the eye.Should I change my Model to improve the View? Is instanceof okay to be used in View classes?

View Replies View Related

Swing/AWT/SWT :: JTree - Drag And Drop Inside One Tree - Java 1.6

Jul 16, 2008

I am trying to drag and drop tree nodes within the same JTree. I have a code which uses Java 1.2 java.awt.dnd.I would like to use TransferHandler and newer implementation.I have found a code which works when JTree is drop target but there is no code where Jtree is drag source and drop target.

View Replies View Related

Rendering Actions In A Combo Box?

Feb 2, 2014

When I add an array of action-objects (the class extends AbstractAction)

to a combo box, I do receive the action performed events, great!

But the combo box items show the long string of the action object, of course!

How to render that string in a way that only the Action.NAME appears?

I was experimenting a little, but could not make it to work:

Java Code: private class ComboRenderer2 extends BasicComboBoxRenderer {
@Override
public Component getListCellRendererComponent(JList list,

[Code]....

View Replies View Related

Swing/AWT/SWT :: Populate JPanel Based On More Information About Selected JTree Node From A File?

Aug 27, 2014

When you select a node in a JTree can you then populate a JPanel based on more information about that node from a file?

View Replies View Related

Rendering The Cells Of JComboBox In Java?

Aug 27, 2014

I have a student class with fields names and Gender. Now, I have a students' array. such that I can create multiple students' classes: student a, student b, student c e.t.c and store them into the students' array. Now, I store this students' array in a JComboBox and want to only display the names of these students in the array. Such that the JComboBox lists only the names of student a, student b and student c. . When a user clicks on a selected Item on the JComboBox, even though, it was a student's name that was selected, I want the selectedItem to be a object of the Student class. This, I have learnt works with JList by writing your own custom JList models and then DefaultListCellRenderer. Is there anyway, one could also do this with JComboBox?

//Main Method
import StudentList;
import Student;
import ViewGui;
import Controller;
public class SwingMainMethod {

[code]....

View Replies View Related

JSF :: CDI With Primefaces Charts Not Rendering Properly

Jun 3, 2014

I have 4 Primefaces bar charts which sometimes renders, sometimes not. In one of them, I inject a http user session attribute and use it to render the chart (the idea is to show only the data that corresponds to the (logged in) user department).

There are 4 session beans which I'm using the javax.enterprise.context.RequestScoped. Sometimes, the Glassfish destroys the instance as expected, but sometimes not.Based on Exception below, how can I resolve it?

The xhtml below shows the main code for only 2 of the 4 bar charts:

<p:tab title="Horas de Treinamento (por Funci)" closable="true" >
<p:barChart id="horasBars" value="#{chartHorasFunci.modelHoras}"
legendPosition="ne"
orientation="horizontal"
seriesColors="AA5555, 00438F"
xaxisLabel="Horas" yaxisLabel="Funcis"
title="34 Horas de Treinamento (Orçado/Realizado) por Funci"

[Code] .....

The Exception:

SEVERE: Error Rendering View[/capacitacao/capacitacao/index.xhtml]
javax.el.ELException: /WEB-INF/include/capacitacao/capacitacao/List.xhtml @145,38 value="#{chartHorasFunci.modelHoras}": org.jboss.weld.exceptions.WeldException: WELD-000049 Unable to invoke private void br.com.bb.upb.diage.atb.capacitacao.beans.ChartHorasFunci.initialize() on br.com.bb.upb.diage.atb.capacitacao.beans.ChartHorasFunci@3e9c727c
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)

[Code] .....

View Replies View Related

JSF :: Element Is Not Rendering / Parsing While Migrating

Jan 24, 2014

I m trying to migrate JSF 1.2 project with myfaces to JSF 2.0 with myfaces 2.0 jars on weblogic10.3 server. Found some problem related build and publishing after resolving them when i hitting my application all JSF html tags are coming in browser as it is they are parsed to html tags. all h: tages are coming as it is on my browser they are not converted to html tags for browser display.

View Replies View Related

JavaFX 2.0 :: Rendering Text Along A Curve

Nov 8, 2014

I'm currently working on a project which requires to have text displayed along a curve. If found this entry a good starting point. It works fine for me on my develompment machine, however the customer on his machine noticed some issues.

The basic idea is to define a path for the text, explode the text into the separate characters and animate them along the path the fraction of the character of the whole lenght. So with a animation duration of 10 seconds and a label of ten characters, the first character would be animated along 1 second, the second 2, and so forth.

This is done by jumping to the designated time in the animation, start the animation and stop it immediately.

Now the problem as I see it, for stopping the animation a separate timer is used, so it can happen that at the time the animation is actually stopped, the animation moved further than the first frame. The effect is that the last characters of the text appear in front (wrapped around).

As I have no evidence to prove or disprove my theory, what do you think is this plausable? I can see a workaround for this issue by defining a path for each character and then let the animation run to the end. While I can set the duration of the animation to 1 ms which should not be visible to the human eye, I'm not able to make the characters invisible and turn the visiblity on when the animation finishes, they always become visible at the start.

Or create my own animation/transition for placing the characters.

View Replies View Related

JavaFX 2.0 :: TreeItem And Custom Rendering

May 31, 2014

I am fairly new to FX but well experienced with Swing. Since I am familiar with the Swing concept of rendering a let's say JTree I got problems with the FX model of - in this case - TreeView.
 
I read several documentations about FX. From the API doc of TreeItem I adapted the file browser example to create an own class like this :
 
public class PathTreeItem extends TreeItem<PathTreeItem> implements
        Comparable<PathTreeItem> {
    private boolean firstVisit = true;
    private boolean readable;
    private boolean dir;
    private boolean symlink;

[Code] ...
 
But this did not change anything. I try to override toString() in both classes but even this did not change anything.
 
What I wonder so far:
 
Why is item in PathNodeTreeCell always null?What is the difference between the item I get in the updateItem method and the one I get from getItem() (line 10)How can I connect the PathTreeItem class to the PathNodeTreeCell classShould I always call super() in the constructors? (I delved a little bit in the sources of TreeItem and TreeCell and I found some setup code there )Is it ok to extend TreeItem in the way I does for my custom PathTreeItem class? ( I wonder if this is a cyclic dependency when I extends TreeItem in this way )How can I sort the nodes? I added the Comparable interface but this not change the sorting of the nodesAre ther some tutorials of TreeItem/TreeCell with no trivial objects like String ? 

I want to adapt an well running Swing application to FX. In the Swing app I used a mechanism to load the child path's of a directory in a separate thread to avoid freezing if the UI if there are much child elements. I guess in FX I should use the Properties pattern to achieve this should I?

View Replies View Related

JavaFX 2.0 :: Triangle Mesh Rendering

Aug 7, 2014

I'm new to JavaFX and I'm exploring its 3D capabilities, and in particular the TriangleMesh visualisation.
 
I have developed a very basic application, based on the Molecule Sample Application provided in the examples, that read a mesh file generated by an external tool (Gmsh) and displays it. Pretty basic.
 
My problem is that the rendering is not what I expected (see attachement)
  
My guess is that I got something wrong with the texture coordinates or the triangles orientation.

- I don't what to have textures attached to my meshes. These are 3D meshes used for scientific simulation purposes. I thus have set all texCoords to 0.
- I don't control the orientation of my triangles, they are generated by Gmsh. Their orientation is also not interesting for my end users so I would like to display all triangles the same way. I used the meshView.setCullFace(CullFace.NONE); method.

View Replies View Related

JSF :: Rendering A Page Using EJBs Between Separate Applications

Oct 16, 2014

I would like users in an application to be able to access and edit their user profiles (Application A). The problem is that the user objects (entities, dao, beans) are handled in a separate application (Application B) which is specifically for managing user accounts. Importing the java sources for App B into App A could be messy and might need configuration of the persistence unit and connection. I'm thinking it would be better to inject an EJB from App B to App A to query the user DB and return the results so a user profile form is rendered in App A.

I know how to inject EJBs within the same application, but I'm not so sure about how it's done across different applications or even if that's the most advisable way to achieve what I want. it's better practice to inject an external EJB into App A or simply import the classes from App B and use those.

@Stateless
public class UsersDaoImpl implements UsersDAO {
@PersistenceContext
private EntityManager em;

[code]....

View Replies View Related

JavaFX 2.0 :: HTML Rendering With Webview Component

Nov 14, 2014

I have a big issue to render this html page with the webview component :
 
<html><head lang="en">  <meta charset="UTF-8">  <title>Pb Rotate</title>  <style type="text/css">   #myDivRotate {
color: purple;   background-color: #d8da3d;   height: 200px;   width: 300px;   margin-top: 20px;   margin-left:20px;   -webkit-transform:perspective(400px) rotateX(30deg);   -webkit-backface-visibility: visible;   }
   </style></head><body>  <div id="myDivRotate">   Coucou
   </div></body></html>

The problem is from "perspective" in -webkit-transform. Without it's ok. But with this one, the result is different from a standard browser like chrome or safari.

View Replies View Related

Rendering Multiple Image Objects From Array In Location

Jan 11, 2015

Untitled.jpg I have been working over this game lately, and i have managed to render multiple images from an array. in this fashion. I created a Main() class with the following in it:

public Main() {
for (int i = 0; i < fuel.length; i++) {
Random r = new Random(); 
changef = r.nextBoolean();
y = (-600 * i) + r.nextInt(300);
if (changef)
fx = 325;
else

[Code]...

Also, this is the Fuel image class and Obstacle image class:

public void tick(Player2 p2) {
y += dy;
Random r = new Random();
if(x >= p2.getH()) {
y = -40 - r.nextInt(700);

[Code]...

(Fuel and obstacle class are identical but separate for better accessibility) I even have player class with an image listening to key events and also a scrolling background. The problem is when i run the game, the images of obstacles render themselves as i want, except for that they overlap each other, i need to prevent over lapping of this images. The fuel is read and obs is black. Heres a glance of how it looks.

View Replies View Related

Java 1.8 - Rendering Images To Printer / Result Is Not Good

Feb 10, 2015

I have some troubles rendering images to the printer, any resolution does not work, even 72 in PDF printer does not work, the image is crappy.

I use the following code but the result is not good. I mean the image quality is not acceptable.

img=new ImageIcon("c:\test\m.jpg").getImage();
scale=72/300d;
g.scale(scale,scale);
g.drawImage(img, 0, 0, (int) (img.getWidth(null)/scale), (int) (img.getHeight(null)/scale), null);

I've also tried :

img=new ImageIcon("c:\test\m.jpg").getImage();
AffineTransform aft=g.getTransform();
double scale=aft.getScaleX();
g.scale(scale,scale);
g.drawImage(img, 0, 0, (int) (img.getWidth(null)/scale), (int) (img.getHeight(null)/scale), null);

The result is the same even if I change the image, very poor and unacceptable!

View Replies View Related

Rendering Images Of Type BufferedImage - Pixels Are Not Consistent In Size

Jun 26, 2014

As implied by the title, when I am rendering images of the type "BufferedImage" unto a Swing application, the images' pixels are not consistent in size. Some might be larger than other, and some might be smaller than other.

Here is a screenshot of what I am talking about (you might need to zoom in a bit because the image is so small): [URL] ....

And here is also some code for you. The images are actually from a sprite sheet, which I first load in its entirety and then split up in an array.

Java Code:

public static BufferedImage sprites[];
...
public void loadSprites(){
try{
BufferedImage bigImage = ImageIO.read(new File("SOURCE/BLA/BLA/THIS/IS/ACTUALLY/NOT/THE/REAL/SOURCE/IN/CASE/YOU'RE/WONDERING/I/JUST/DON'T/WANT/YOU/TO/FIND/ME/AND/RAPE/ME"));
sprites = new BufferedImage[16 * 16];

[Code] ....

So, how do I make the pixels equally small?

View Replies View Related

Set Icon Of File Depending On What Is In It - Like PNG

Feb 15, 2014

So I'm in the middle of creating a model program with voxels. I want to be able to see how the model looks like when I'm in for example my documents (not inside the real program). I want it to show an image of the model, just like a png file shows its image. I've tried looking around, but I've only found threads about changing exe files icon.

Image example:

So, is this possible in Java or do I need to use c/c++ (with JNA) to make this possible?

Or is it not possible at all?

View Replies View Related

How To Resize Icon Of Button

Jan 30, 2015

So I have got a button and there is this property assigned to it:

button.setIcon(new ImageIcon("srcimage.jpg"));

The icon is not displayed in full, as it is larger than the button. What property can I use to resize the icon? I have tried few and it did not work.

View Replies View Related

Swing/AWT/SWT :: Setting Icon On JButton

Feb 23, 2014

Recently I have been working on an executable launcher. I tried to get the executable icons and set them on the JButtons. Still there are some problems. Here is a part of the code:

try {
button[i].setIcon(FileSystemView.getFileSystemView().getSystemIcon(new File(getConfig("path." + (i+1)))));
}
catch (NullPointerException ex) {
}

Here the getConfig() method is already defined to get a string in a "properties" file. However, the icons are very small and they don't fill the entire button.

How can the icon fill the entire button (for example, having a custom size of 48x48, or automatically filled the button)? The frame will not be resized.

Here is the whole code...

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.io.File.*;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: How To Resize Image Icon

Aug 15, 2001

Any way to resize an ImageIcon when placing it on a Button so that I don't have to physically rezize the image file?? I am writing an Application, not an applet, so the getImage method won't work.

View Replies View Related

Java GUI Displaying Image Icon

Dec 2, 2014

how to display a jpg image on a through a Jlabel. I am sure it is a simple error but I am still new to GUI's. line 31 to 35 you can see the ImageIcon and file wrapped in the JLabel. I verified its in the correct location and file name, but usually fails (i thought) when it is not correct.

Java Code:

import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

[code]....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved