jlist

Java - Deprecated method - What to do?

那年仲夏 提交于 2019-11-30 17:33:48
问题 I am following a series of Java tutorials in an attempt to learn it. I have a question about tutorial 72. Link: http://www.youtube.com/watch?v=9z_8yEv7nIc&feature=relmfu At 7:02 of the video, this statement is written. However, this method has been deprecated in Java 1.7. RightList.setListData(LeftList.getSelectedValues()); Eclipse returns the following error: Object[] javax.swing.JList.getSelectedValues() getSelectedValues @Deprecated public Object[] getSelectedValues() Deprecated. As of JDK

Java JList model

半城伤御伤魂 提交于 2019-11-30 17:25:16
问题 How can I make a list model from a JList in order to be able to insert an item into it. I want to use this method: addElement(java.lang.Object item) I found an explanation here, but the problem is that ListModel is an interface and even if I write an implementation and override its method, I can't use the addElement() method 回答1: Java provides implementations of ListModel already, like DefaultListModel, that you can instantiate and use For example: final DefaultListModel model = new

Expand JList row height depending on content

故事扮演 提交于 2019-11-30 09:18:55
问题 I have a simple problem which totally drives me crazy. I have a JList, and would like its cells to expand depending on their content, which is text of variable length. So I created a CustomCellRenderer like so: @Override public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean hasFocus) { final String text = (String) value; final JTextArea ta = new JTextArea(); ta.setText(text); ta.setFont(new Font("Dialog",

How to generate a Jlist with alternating colors

隐身守侯 提交于 2019-11-30 09:02:32
In Java how do I get a JList with alternating colors? Any sample code? To customize the look of a JList cells you need to write your own implementation of a ListCellRenderer . A sample implementation of the class may look like this: (rough sketch, not tested) public class MyListCellThing extends JLabel implements ListCellRenderer { public MyListCellThing() { setOpaque(true); } public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { // Assumes the stuff in the list has a pretty toString setText(value.toString()); // based on

Word wrap in JList items

▼魔方 西西 提交于 2019-11-30 03:03:14
问题 I have a JList with very long item names that cause the horizontal scroll-bar to appear in scroll-pane. Is there anyway that I can word wrap so that the whole whole item name appears in 2 rows yet can be selected in one click? I.E it should still behave as a single item but be displayed in two rows. Here is what I did after seeing the example below I added a new class to my project MyCellRenderer and then I went added MyList.setCellRenderer(new MyCellRenderer(80)); in the post creation code

How do you change border of the pop up section of a JComboBox?

ⅰ亾dé卋堺 提交于 2019-11-29 16:44:38
I wan't to change the border of the popup/selection part of the JComboBox. Note that the UI is BasicComboBoxUI I've tried: weaponCB.setRenderer(new DefaultListCellRenderer() { @Override public void paint(Graphics g) { setBorder(whiteBorder) //whiteBorder is a white border super.paint(g); } }); but it gave me this: and: for (int i=0; i<weaponCB.getComponentCount(); i++) { if (weaponCB.getComponent(i) instanceof AbstractButton) { ((AbstractButton)weaponCB.getComponent(i)).setBorder(whiteBorder); } } but it gave me this: what i wan't is something like this: (it was done in photoshop) I don't mind

Problem with reusing the JScrollPane again for different custom Lists

﹥>﹥吖頭↗ 提交于 2019-11-29 16:40:26
I am trying to create a JScrollPane component which can be reused depending upon the string parameter that is being passed.. I have created the following code, it works if I use JFrame to embed the JScrollPane inside it, but when I try to reuse the code in creating different JScrollPane the scrollPane is not displayed at all.. I am implementing it in a java swing project.. Please let me know what should be done in this..any suggestions are highly appreciated. The same problem I have with regards to the JComboBox, it doesn't display... public class ListComponent extends JScrollPane { private

Expand JList row height depending on content

耗尽温柔 提交于 2019-11-29 14:31:25
I have a simple problem which totally drives me crazy. I have a JList, and would like its cells to expand depending on their content, which is text of variable length. So I created a CustomCellRenderer like so: @Override public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean hasFocus) { final String text = (String) value; final JTextArea ta = new JTextArea(); ta.setText(text); ta.setFont(new Font("Dialog", Font.PLAIN, (int) Theme.FONTSIZE_TEXT)); ta.setForeground(Theme.FONTCOLOR_CONTENT); ta.setLineWrap(true)

Can Items in a JList be formatted as HTML

我怕爱的太早我们不能终老 提交于 2019-11-29 14:02:00
I would like to create a JList in Java so that each individual item is formattted using HTML tags, but I'm not clear how to do this or even if this is possible. Does anyone have any suggestions? Thank you. Its actually very simple. For every string in the list surround it with the html tags such as this: <html><font color=green>this will be green</font></html> When the JList displays it it will be green. Swing supports the use of HTML in many of the controls that display text. In your case the JList is actually using a JLabel to display each item, so you just need the list model to return the

JList add/remove Item

北慕城南 提交于 2019-11-29 13:36:46
Hi I have to pick an element from a JList to another, removing it from the first The method I've created inserts only one element, overwriting the last one and doesn't remove the selected item from the first JList Here's the code: First list private javax.swing.JList listaRosa; Populated by this method: private void visualizzaRosaButtonvisualizzaRosa(java.awt.event.ActionEvent evt) { // TODO add your handling code here: visualizzaSquadraSelezionata(); String fileSquadra; fileSquadra = squadraDaVisualizzare.getText(); DefaultListModel listModel = new DefaultListModel(); try { FileInputStream