Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualppgamedev

Posted 01 November 2012 - 08:34 AM

You could walk the extra mile with a "renderer".

I honestly love you man thanks!!

But I warn you: I'm happily married Posted Image

[source lang="java"] private void createItemSelection() { itemSelection = new JComboBox<HardwareItem>(); itemSelection.setModel(createItemSelectionModel()); itemSelection.setRenderer(createItemSelectionRenderer()); } public boolean addTabs() { HardwareStock stock = store.getStock(); itemSelection.removeAllItems(); itemSelection.addItem(null); for (int i = 0; i < stock.listSize(); i++) { itemSelection.addItem(stock.elementAt(i)); } return stock.listSize() > 0; } @SuppressWarnings("unchecked") private ListCellRenderer<HardwareItem> createItemSelectionRenderer() { return new BasicComboBoxRenderer() { private static final long serialVersionUID = 1L; @Override public Component getListCellRendererComponent( @SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus ) { Component rendererComponent = super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus); HardwareItem item = (HardwareItem) value; String text = (item == null) ? "Pick an item" : item.getItemName(); setText(text); return rendererComponent; } }; } private ComboBoxModel<HardwareItem> createItemSelectionModel() { MutableComboBoxModel<HardwareItem> model = new DefaultComboBoxModel<HardwareItem>(); model.addElement(null); return model; }[/source]

For some reason I cannot properly visualise the code with my browser Posted Image

#8ppgamedev

Posted 01 November 2012 - 08:32 AM

You could walk the extra mile with a "renderer".

I honestly love you man thanks!!

But I warn you: I'm happily married Posted Image

[source lang="java"] private void createItemSelection() { itemSelection = new JComboBox<HardwareItem>(); itemSelection.setModel(createItemSelectionModel()); itemSelection.setRenderer(createItemSelectionRenderer()); } public boolean addTabs() { HardwareStock stock = store.getStock(); itemSelection.removeAllItems(); itemSelection.addItem(null); for (int i = 0; i < stock.listSize(); i++) { itemSelection.addItem(stock.elementAt(i)); } return stock.listSize() > 0; } @SuppressWarnings("unchecked") private ListCellRenderer<HardwareItem> createItemSelectionRenderer() { return new BasicComboBoxRenderer() { private static final long serialVersionUID = 1L; @Override public Component getListCellRendererComponent( @SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus ) { Component rendererComponent = super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus); HardwareItem item = (HardwareItem) value; String text = (item == null) ? "Pick an item" : item.getItemName(); setText(text); return rendererComponent; } }; } private ComboBoxModel<HardwareItem> createItemSelectionModel() { MutableComboBoxModel<HardwareItem> model = new DefaultComboBoxModel<HardwareItem>(); model.addElement(null); return model; }[/source]

#7ppgamedev

Posted 01 November 2012 - 08:30 AM

You could walk the extra mile with a "renderer".

I honestly love you man thanks!!

But I warn you: I'm happily married Posted Image

[source lang="java"] private void createItemSelection() { itemSelection = new JComboBox<HardwareItem>(); itemSelection.setModel(createItemSelectionModel()); itemSelection.setRenderer(createItemSelectionRenderer()); }[/source]
[source lang="java"] public boolean addTabs() { HardwareStock stock = store.getStock(); itemSelection.removeAllItems(); itemSelection.addItem(null); for (int i = 0; i < stock.listSize(); i++) { itemSelection.addItem(stock.elementAt(i)); } return stock.listSize() > 0; }[/source]
[source lang="java"] @SuppressWarnings("unchecked") private ListCellRenderer<HardwareItem> createItemSelectionRenderer() { return new BasicComboBoxRenderer() { private static final long serialVersionUID = 1L; @Override public Component getListCellRendererComponent( @SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus ) { Component rendererComponent = super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus); HardwareItem item = (HardwareItem) value; String text = (item == null) ? "Pick an item" : item.getItemName(); setText(text); return rendererComponent; } }; }[/source]
[source lang="java"] private ComboBoxModel<HardwareItem> createItemSelectionModel() { MutableComboBoxModel<HardwareItem> model = new DefaultComboBoxModel<HardwareItem>(); model.addElement(null); return model; }[/source]

#6ppgamedev

Posted 01 November 2012 - 08:29 AM

You could walk the extra mile with a "renderer".

I honestly love you man thanks!!

But I warn you: I'm happily married Posted Image

[source lang="java"] private void createItemSelection() { itemSelection = new JComboBox<HardwareItem>(); itemSelection.setModel(createItemSelectionModel()); itemSelection.setRenderer(createItemSelectionRenderer()); } public boolean addTabs() { HardwareStock stock = store.getStock(); itemSelection.removeAllItems(); itemSelection.addItem(null); for (int i = 0; i < stock.listSize(); i++) { itemSelection.addItem(stock.elementAt(i)); } return stock.listSize() > 0; } @SuppressWarnings("unchecked") private ListCellRenderer<HardwareItem> createItemSelectionRenderer() { return new BasicComboBoxRenderer() { private static final long serialVersionUID = 1L; @Override public Component getListCellRendererComponent( @SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus ) { Component rendererComponent = super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus); HardwareItem item = (HardwareItem) value; String text = (item == null) ? "Pick an item" : item.getItemName(); setText(text); return rendererComponent; } }; } private ComboBoxModel<HardwareItem> createItemSelectionModel() { MutableComboBoxModel<HardwareItem> model = new DefaultComboBoxModel<HardwareItem>(); model.addElement(null); return model; }[/source]

#5ppgamedev

Posted 01 November 2012 - 08:29 AM

You could walk the extra mile with a "renderer".

I honestly love you man thanks!!

But I warn you: I'm happily married Posted Image

[source lang="java"] private void createItemSelection() { itemSelection = new JComboBox<HardwareItem>(); itemSelection.setModel(createItemSelectionModel()); itemSelection.setRenderer(createItemSelectionRenderer()); } public boolean addTabs() { HardwareStock stock = store.getStock(); itemSelection.removeAllItems(); itemSelection.addItem(null); for (int i = 0; i < stock.listSize(); i++) { itemSelection.addItem(stock.elementAt(i)); } return stock.listSize() > 0; } @SuppressWarnings("unchecked") private ListCellRenderer<HardwareItem> createItemSelectionRenderer() { return new BasicComboBoxRenderer() { private static final long serialVersionUID = 1L; @Override public Component getListCellRendererComponent( @SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus ) { Component rendererComponent = super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus); HardwareItem item = (HardwareItem) value; String text = (item == null) ? "Pick an item" : item.getItemName(); setText(text); return rendererComponent; } }; } private ComboBoxModel<HardwareItem> createItemSelectionModel() { MutableComboBoxModel<HardwareItem> model = new DefaultComboBoxModel<HardwareItem>(); model.addElement(null); return model; }[/source]

#4ppgamedev

Posted 01 November 2012 - 08:27 AM

You could walk the extra mile with a "renderer".

I honestly love you man thanks!!

But I warn you: I'm happily married Posted Image


[source lang="java"]private void createItemSelection() { itemSelection = new JComboBox<HardwareItem>(); itemSelection.setModel(createItemSelectionModel()); itemSelection.setRenderer(createItemSelectionRenderer());}public boolean addTabs() { HardwareStock stock = store.getStock(); itemSelection.removeAllItems(); itemSelection.addItem(null); for (int i = 0; i < stock.listSize(); i++) { itemSelection.addItem(stock.elementAt(i)); } return stock.listSize() > 0;}private ListCellRenderer<HardwareItem> createItemSelectionRenderer() { return new BasicComboBoxRenderer() { private static final long serialVersionUID = 1L; public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component rendererComponent = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); HardwareItem item = (HardwareItem) value; String text = (item == null) ? "Pick an item" : item.getItemName(); setText(text); return rendererComponent; } };}[/source]

PARTNERS