kendavidson78
New Member
I have the following code:\[code\]package gui;import java.awt.Component;import java.util.ArrayList;import java.util.Observable;import java.util.Observer;import javax.swing.BorderFactory;import javax.swing.DefaultListCellRenderer;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.ListCellRenderer;import javax.swing.border.Border;import javax.swing.border.EtchedBorder;import javax.swing.border.TitledBorder;import org.hibernate.Criteria;import org.hibernate.SQLQuery;import org.hibernate.classic.Session;import Hibernate.ExtendedPaperData;import Hibernate.JournalData;import Hibernate.PaperData;import Hibernate.ReferencesData;import Hibernate.SQLCreatorFactory;import Hibernate.SearchQueryCreator;import Hibernate.SearchQueryResult;public class CompoundBorderListRenderer implements ListCellRenderer{ protected static Border loweredBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); protected static Border loweredBevelBorder = BorderFactory.createLoweredBevelBorder(); protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer(); protected Session session; public CompoundBorderListRenderer(Session session) { this.session = session; } @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus); String totalValue; ExtendedPaperData paper = (ExtendedPaperData) value; String title = paper.getTitle(); StringBuffer references = new StringBuffer(); TitledBorder titleBorder; if(cellHasFocus) { titleBorder = new TitledBorder(loweredBevelBorder,title); SearchQueryCreator creator = SQLCreatorFactory.getInstance().get("references"); String sqlQuery = creator.makeSQLSearchQuery(String.valueOf(paper.getTableId())); SearchQueryResult result = new SearchQueryResult(); SQLQuery query = session.createSQLQuery(sqlQuery); query.addEntity(ReferencesData.class); query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); java.util.List<ReferencesData> queryRefrences = (java.util.List<ReferencesData>) query.list(); if(queryRefrences.size() > 0) { for(ReferencesData foundReference: queryRefrences) { creator = SQLCreatorFactory.getInstance().get("paper id"); sqlQuery = creator.makeSQLSearchQuery(String.valueOf(foundReference.getTableId())); result = new SearchQueryResult(); query = session.createSQLQuery(sqlQuery); query.addEntity(PaperData.class); query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); java.util.List<PaperData> queryPapers = (java.util.List<PaperData>) query.list(); references.append("Title: " + queryPapers.get(0).getTitle() + "<BR>" + "Authors: " + queryPapers.get(0).getAuthors() + "<BR>"); } } totalValue = http://stackoverflow.com/questions/15853711/paper.toString() + references.toString(); } else { titleBorder = new TitledBorder(loweredBorder,title); totalValue ="Authors: " + paper.getAuthors() + "<BR>" + "Journal: "+ paper.getJournalName(); } renderer.setBorder(titleBorder); renderer.setText("<HTML>" + totalValue + "</HTML>"); list.setFixedCellHeight(Short.MAX_VALUE); return renderer; }}\[/code\]When I make a double click on item of JList, I want to search some information and add this additional information to the JList which already exists and it shows some item. So, I want to replace some text which is in the item on another text. This text will be much longer. When I click on another item? new information should be added and old value must be restored. I made all things except changing the size of the item. When I add a text which is much longer than existing text in the item JList can't locate it. I have an overlapped text:Before clicking on the item:
After clicking on the item:
Please help, how is it possible to locate it in a good way?