if(userInput.equals("ListLayout")) { CustomLayout layout = new ListLayout(); } else if (userInput.equals("GridLayout")) { CustomLayout layout = new GridLayout(); }
if ("ListLayout".equals(userInput)) { return new ListLayout(); }
public class CustomLayoutFactory { public CustomLayout createInstance(String layoutName) { if("ListLayout".equals(layoutName) { return new ListLayout(); } else if("GridLayout".equals(layoutName) { return new GridLayout(); } return null; } }
String userInput = //get user's input while(!userInput.equalsIgnoreCase("ListLayout") && !userInput.equalsIgnoreCase("gridLayout")){ System.out.println("Please enter a valid option"); userInput = //get user's input again } CustomLayout layout; if(userInput.equalsIgnoreCase("ListLayout") layout = new ListLayout(); else layout = new GridLayout();
JFrame frame = new JFrame(); JPanel content = new JPanel(); content.setLayout(new ListLayout(25)); JScrollPane scroll = new JScrollPane(content); for (int i = 0; i < 20; ++i) { content.add(new JButton(Integer.toString(i))); } frame.setContentPane(scroll); frame.pack(); frame.setVisible(true);
/** * Creates a new {@link JEventListPanel} hosting the * {@link JComponent}s from the specified source {@link EventList}. */ public JEventListPanel(EventList<E> source, Format<E> format) { this.swingSource = GlazedListsSwing.swingThreadProxyList(source); this.listLayout = new ListLayout(this, format); this.format = format; this.setLayout(listLayout); // populate the initial elements for(int i = 0; i < swingSource.size(); i++) { sourceChangeHandler.insert(i); } // listen for changes to the source swingSource.addListEventListener(sourceChangeHandler); }
/** * Creates a new {@link JEventListPanel} hosting the * {@link JComponent}s from the specified source {@link EventList}. */ public JEventListPanel(EventList<E> source, Format<E> format) { this.swingSource = GlazedListsSwing.swingThreadProxyList(source); this.listLayout = new ListLayout(this, format); this.format = format; this.setLayout(listLayout); // populate the initial elements for(int i = 0; i < swingSource.size(); i++) { sourceChangeHandler.insert(i); } // listen for changes to the source swingSource.addListEventListener(sourceChangeHandler); }
/** * Creates a new {@link JEventListPanel} hosting the * {@link JComponent}s from the specified source {@link EventList}. */ public JEventListPanel(EventList<E> source, Format<E> format) { this.swingSource = GlazedListsSwing.swingThreadProxyList(source); this.listLayout = new ListLayout(this, format); this.format = format; this.setLayout(listLayout); // populate the initial elements for(int i = 0; i < swingSource.size(); i++) { sourceChangeHandler.insert(i); } // listen for changes to the source swingSource.addListEventListener(sourceChangeHandler); }