Java Code Examples for javax.swing.JList#getInsets()

The following examples show how to use javax.swing.JList#getInsets() . 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: MemberCellRenderer.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<? extends Member> list,
		Member member, int index, boolean isSelected, boolean cellHasFocus) {
	label.setText(member.getName());
	if (member.isLeader()) {
		label.setFont(boldFont);
	} else {
		label.setFont(normalFont);
	}

	/*
	 * This is very, very ugly. JList does not resize the component
	 * normally, so the StatusDisplayBar never gets the chance to update
	 * the model. Try to figure out the correct width.
	 */
	Insets insets = hpBar.getInsets();
	int barWidth = list.getWidth() - insets.left - insets.right - 2;
	insets = list.getInsets();
	barWidth -= insets.left + insets.right;
	hpBar.getModel().setMaxRepresentation(barWidth);

	if (member.isPresent()) {
		hpBar.setPresent(true);
		hpBar.setRatio(member.getHpRatio());
	} else {
		hpBar.setPresent(false);
	}

	return renderer;
}
 
Example 2
Source File: ToolFilterPanel.java    From chipster with MIT License 5 votes vote down vote up
public ToolFilterPanel(ToolPanel parent,
       List<ToolCategory> categories) {
    super(new GridLayout(1, 2));
    this.toolPanel = parent;
    this.categories = categories;
    
    categoryList = new JList();
    categoryList.setSelectedIndex(0);
    categoryList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    categoryList.addListSelectionListener(this);
    categoryList.setCellRenderer(new ToolSelectorPanel.CategoryListRenderer());
    categoryList.getInsets().right = 1;
    categoryList.setName("categoryList");
    
    // Operation list shows the results
    visibleOperationsList = new JList();
    visibleOperationsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    visibleOperationsList.addListSelectionListener(this);
    visibleOperationsList.setCellRenderer(new ToolSelectorPanel.FontSizeFriendlyListRenderer());
    visibleOperationsList.getInsets().right = 1;
    visibleOperationsList.setName("operationList");
    
    JScrollPane categoryListScroller = new JScrollPane(categoryList);       
    JScrollPane operationListScroller = new JScrollPane(visibleOperationsList);
    categoryListScroller.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1,
            VisualConstants.TOOL_LIST_BORDER_COLOR));
    operationListScroller.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

    this.add(categoryListScroller);
    this.add(operationListScroller);        
}
 
Example 3
Source File: ToolSelectorPanel.java    From chipster with MIT License 5 votes vote down vote up
/**
 * Creates a new ToolSelectorPanel.
 * 
 * @param parent The ToolPanel, for communication purposes.
 */
public ToolSelectorPanel(ToolPanel parent, ToolModule toolModule) {
	super(new GridLayout(1, 2));
	this.toolPanel = parent;
	this.toolModule = toolModule;
	
       List<ToolCategory> toolCategories;
       toolCategories = Collections.list(Collections.enumeration(toolModule.getVisibleCategories()));
       
	categoryList = new JList();
	categoryList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	categoryList.addListSelectionListener(this);
	categoryList.setCellRenderer(new CategoryListRenderer());
	categoryList.getInsets().right = 1;
	categoryList.setName("categoryList");
	categoryList.setListData(toolCategories.toArray());
	
	
	
	toolList = new JList();
	toolList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	toolList.addListSelectionListener(this);
	toolList.setCellRenderer(new FontSizeFriendlyListRenderer());
	toolList.addMouseListener(new MouseClickListener());
	toolList.getInsets().right = 1;
	toolList.setName("toolList");
	
	JScrollPane categoryListScroller = new JScrollPane(categoryList);		
	JScrollPane toolListScroller = new JScrollPane(toolList);
	
	//Remove useless borders
	categoryListScroller.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1,
	        VisualConstants.TOOL_LIST_BORDER_COLOR));
	toolListScroller.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
	
	this.add(categoryListScroller);
	this.add(toolListScroller);
}