Search Results

Search found 1571 results on 63 pages for 'swing'.

Page 37/63 | < Previous Page | 33 34 35 36 37 38 39 40 41 42 43 44  | Next Page >

  • Set the amount of rows JList show (Java)

    - by Alex Cheng
    Hi all. Problem: I have a method that creates a list from the parsed ArrayList. I manage to show the list in the GUI, without scrollbar. However, I am having problem setting it to show only the size of ArrayList. Meaning, say if the size is 6, there should only be 6 rows in the shown List. Below is the code that I am using. I tried setting the visibleRowCount as below but it does not work. I tried printing out the result and it shows that the change is made. private void createSuggestionList(ArrayList<String> str) { int visibleRowCount = str.size(); System.out.println("visibleRowCount " + visibleRowCount); listForSuggestion = new JList(str.toArray()); listForSuggestion.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listForSuggestion.setSelectedIndex(0); listForSuggestion.setVisibleRowCount(visibleRowCount); System.out.println(listForSuggestion.getVisibleRowCount()); listScrollPane = new JScrollPane(listForSuggestion); MouseListener mouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent mouseEvent) { JList theList = (JList) mouseEvent.getSource(); if (mouseEvent.getClickCount() == 2) { int index = theList.locationToIndex(mouseEvent.getPoint()); if (index >= 0) { Object o = theList.getModel().getElementAt(index); System.out.println("Double-clicked on: " + o.toString()); } } } }; listForSuggestion.addMouseListener(mouseListener); textPane.add(listScrollPane); repaint(); } To summarize: I want the JList to show as many rows as the size of the parsed ArrayList, without a scrollbar. Any ideas? Please help. Thanks. Please let me know if a picture of the problem is needed in case I did not phrase my question correctly.

    Read the article

  • How can I force the text go to the button of the panel?

    - by Roman
    At the moment I have the following code which works fine. label = new JLabel(panelLabel,SwingConstants.CENTER); outputPanel.add(label,BorderLayout.CENTER); I get the text in the center of the panel (in terms of the left-right position as well as in terms of the top-bottom). Now I want to set the position to the bottom (and center in terms of "left-right"). I tried to use SOUTH instead of the CENTER in the first line. Compiler does not complains but during the execution i get IllegalArgumentException: HorizontalAlignment. What is that?

    Read the article

  • What's the fastest way to draw a Hello World in Java

    - by Mordan
    What's the fastest way to draw a Hello World on the screen as a GUI in Java, 1- by using the minimum number of classes. 2- with the least byte code executed 2- the JVM tweaks so when I double click on the Jar file in Windows, the Hello World appears in no time (assuming the Runtime is not already loaded).

    Read the article

  • Add other components to JFrame with background

    - by bnabilos
    Hello, I want to add a background image to my JFrame but when I do it using the code below, I'm unable to add other elements like JLabel or JTextField. ImageIcon icon = new ImageIcon("src/images/back.jpg"); backImage = icon.getImage(); BackgroundImagePanel contentPane = new BackgroundImagePanel(); contentPane.setBackgroundImage(backImage); this.setContentPane(contentPane); Can you tell me please if there is another way to add JTabbedPane to a JFrame with a background ? Thank you.

    Read the article

  • InputVerifier don't display each component icon(lable)

    - by Sajjad
    I have a form that set a input verifier to it. I want when a user type a correct value for a text field and want to go to other text field, a check icon should be display besides of text field. But now in my code, when user type a correct value on first text field an go to other, Two icons displayed together! public class UserDialog extends JDialog { JButton cancelBtn, okBtn; JTextField fNameTf, lNameTf; JRadioButton maleRb, femaleRb; ButtonGroup group; JLabel fNameLbl, fNamePicLbl, lNameLbl, lNamePicLbl, genderLbl, tempBtn, temp3; public UserDialog() { add(createForm(), BorderLayout.CENTER); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setLocation(400, 100); pack(); setVisible(true); } public JPanel createForm() { JPanel panel = new JPanel(); ImageIcon image = new ImageIcon("Check.png"); okBtn = new JButton("Ok"); cancelBtn = new JButton("Cancel"); tempBtn = new JLabel(); fNameLbl = new JLabel("First Name"); fNamePicLbl = new JLabel(image); fNamePicLbl.setVisible(false); lNameLbl = new JLabel("Last Name"); lNamePicLbl = new JLabel(image); lNamePicLbl.setVisible(false); genderLbl = new JLabel("Gender"); maleRb = new JRadioButton("Male"); femaleRb = new JRadioButton("Female"); temp3 = new JLabel(); group = new ButtonGroup(); group.add(maleRb); group.add(femaleRb); fNameTf = new JTextField(10); fNameTf.setName("FnTF"); fNameTf.setInputVerifier(new MyVerifier(new JComponent[]{maleRb, femaleRb, okBtn})); lNameTf = new JTextField(10); lNameTf.setName("LnTF"); lNameTf.setInputVerifier(new MyVerifier(new JComponent[]{maleRb, femaleRb, okBtn})); panel.add(fNameLbl); panel.add(fNameTf); panel.add(fNamePicLbl); panel.add(lNameLbl); panel.add(lNameTf); panel.add(lNamePicLbl); panel.add(genderLbl); JPanel radioPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); radioPanel.add(maleRb); radioPanel.add(femaleRb); panel.add(radioPanel); panel.add(temp3); panel.add(okBtn); panel.add(cancelBtn); panel.add(tempBtn); panel.setLayout(new SpringLayout()); SpringUtilities.makeCompactGrid(panel, 4, 3, 50, 10, 80, 60); return panel; } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new UserDialog(); } }); } public class MyVerifier extends InputVerifier { private JComponent[] component; public MyVerifier(JComponent[] components) { component = components; } @Override public boolean verify(JComponent input) { String name = input.getName(); if (name.equals("FnTF")) { String text = ((JTextField) input).getText().trim(); if (text.matches(".*\\d.*") || text.length() == 0) { //disable dependent components for (JComponent r : component) { r.setEnabled(false); } return false; } } else if (name.equals("LnTF")) { String text = ((JTextField) input).getText(); if (text.matches(".*\\d.*") || text.length() == 0) { //disable dependent components for (JComponent r : component) { r.setEnabled(false); } return false; } } //enable dependent components for (JComponent r : component) { r.setEnabled(true); } fNamePicLbl.setVisible(true); lNamePicLbl.setVisible(true); return true; } } } }

    Read the article

  • Getting hold of a reference to the object created by JOptionPane static methods

    - by user548240
    Hi, I wonder if it is possible to get hold of a reference to the (JDialog?) object created by one of those static methods of JOptionPane (e.g. showMessageDialog)? I intend to modify the position where the dialog appears on the screen. More specifically, I want the dialog to appear at the top-left corner of the main app window, instead of the centre of the window by default. So having a reference to the object would enable me to use setLocation to achieve the desired effect... Any suggestion would be appreciated! Thanks!

    Read the article

  • how to use a wav file in eclipse

    - by AlphaAndOmega
    I've been trying to add audio to a project I've been doing. I found some code on here for html that is also supposed to work with file but it keeps saying "Exception in thread "main" javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source) at LoopSound.main(LoopSound.java:15)" the code public class LoopSound { public static void main(String[] args) throws Throwable { File file = new File("c:\\Users\\rabidbun\\Pictures\\10177-m-001.wav"); Clip clip = AudioSystem.getClip(); // getAudioInputStream() also accepts a File or InputStream AudioInputStream wav = AudioSystem.getAudioInputStream( file ); clip.open(wav); // loop continuously clip.loop(-1000); SwingUtilities.invokeLater(new Runnable() { public void run() { // A GUI element to prevent the Clip's daemon Thread // from terminating at the end of the main() JOptionPane.showMessageDialog(null, "Close to exit!"); } }); } } What is wrong with the code?

    Read the article

  • java: how to make srollable panel with radio button and labels inside?

    - by Lucia
    Hi, I got a JScrollPane in which I want to place a list of radio buttons and labels. My problem is the panel doesn't scroll, I suppose it's because i didn't set a viewport, but how can I set it when I have to many components? My code looks something like this: JScrollPane panel = new JScrollPane(); JRadioButton myRadio; JLabel myLabel; for(int i = 0; i<100; i++){ myRadio = new JRadioButton(); myLabel = new JLabel("text"); panel.add(myRadio); panel.add(myLabel); } Thanks.

    Read the article

  • JFileChooser select directory but show files

    - by Jeff Storey
    I feel like there should be a simple way to do this but I can't figure it out. I have a JFileChooser that allows the user to select directories. I want to show all the files in the directories to give the user some context, but only directories should be accepted as selections (maybe the Open button would be disabled when a file is selected). Is there an easy way of doing this?

    Read the article

  • Image not getting displayed on a JPanel.

    - by Myth17
    class Deal implements ActionListener { public void actionPerformed(ActionEvent e) { dl.setDeck(); dl.shuffle(); dl.firstDraw(pl); for(Card c:pl.showHand()) panelplay.add(new JLabel(c.getImageIcon())); panelplay.validate(); } } This is an event handler for a Jbutton. The method pl.showHand() returns a ArrayList of a user defined class 'Card'. Inserting a println() inside the loop shows the print, so the code is being executed but the Panel panelplay isnt showing card Images.

    Read the article

  • Java jList add item based on combobox selection

    - by Stephan Badert
    I have a csv file that is being loaded in my programme. It contains citys and areas and some other stuff (not important here). Once the csv is selected I load the data into several comboboxes. 1 Thing is not working, I have a combobox containing all the citys and now I need to list all the areas for that country based on selection from the combobox. Here is the event: private void cboProvinciesItemStateChanged(java.awt.event.ItemEvent evt) { //System.out.println(Arrays.asList(gemeentesPerProvincie(gemeentes))); invullenListProvincie(gemeentes); } Here is the method: private void invullenListProvincie(ArrayList<Gemeentes> gemeentes) { Gemeentes gf = (Gemeentes) cboProvincies.getSelectedItem(); DefaultListModel model = new DefaultListModel(); JList list = new JList(model); for (Gemeentes gemeente : gemeentesPerProvincie(gemeentes)) { model.addElement(gemeente); } lstGemeentes.setModel(model); } and this is the method to filter all the areas that equal the selection from the combobox: private ArrayList<Gemeentes> gemeentesPerProvincie(ArrayList<Gemeentes> gemeentes) { String GemPerProv = (String) cboProvincies.getSelectedItem(); ArrayList<Gemeentes> selectie = new ArrayList<Gemeentes>(); for (Gemeentes gemeente : gemeentes) { if (gemeente.getsProvincie().equals(GemPerProv)) { selectie.add(gemeente); } } return selectie; } I am convinced the error is the way I am trying to add items to the jList gemeentesPerProvincie(), I have tried so many things already. I really hope someone can see what i am clearly missing...

    Read the article

  • Is it possible to Hide Text through a Style?

    - by Sandro
    I currently have a JTextPane that will be displaying text coming in from different streams. The way that the user can tell which stream the text came from is that the text from each stream has a different Style to it. Is there a way to make a Style that will hide the text so that I can filter out different pieces of text? Thank you.

    Read the article

  • How to change the jtooltip timers for 1 component.

    - by i30817
    I have a component where i want to display a custom jtooltip. That is easy, just change the getTooltip method. Similar for location and text. However i also want to change the timers. The tooltip should always be displayed if the mouse is over a cellrenderer of the component. If it leaves all of those it should be turned invisible. I know that i can use TooltipManager to control the times globally. But the best solution is probably to just shortcircut that and display the tooltip myself with a mouselistener. However when i tried to do that (unregister the component in TooltipManager and setting the tooltip visible, with text and in the correct position, in a mouse listener) the tooltip never showed at all. What am i doing wrong?

    Read the article

  • Make text appear briefly in a JPanel

    - by Roo
    Hi, I am trying to make text appear briefly before it disappears. It would be along the lines of 1) Set color to black 2) wait x amount of seconds 3) set color to background color The method I call is repaint(), which then calls paintComponent(Graphics painter). repaint() is called only if I press the space-bar. I thought of trying repaint();Thread.sleep(1000);repaint(); (I do catch the Interrupt exception, just not shown), but it only calls paintComponent once per space-bar . Is there an easy way to do this or is this something that is a bit challenging?

    Read the article

  • Adding to existing JList

    - by Máca Danilov
    I need some help about adding items to JList. I work on some "library" kind of project. And I need to add readers to already existing JList. But when I try to add it, JList just resets, removes all the readers and starts adding readers to a new blank JList. But I don't need it to make new list but add it to the already existing one. I know it's something about creating new model after adding, but i don't know where to fix it. panelHorni = new JPanel(); listModel = new DefaultListModel(); listCtenaru = new JList(listModel); FileInputStream fis = new FileInputStream("myjlist.bin"); ObjectInputStream ois = new ObjectInputStream(fis); listCtenaru = (JList)ois.readObject(); listScroll = new JScrollPane(); listScroll.add(listCtenaru); listCtenaru.setPreferredSize(new Dimension(350, 417)); listCtenaru.setBackground(new Color(238,238,238)); panelHorni.add(listCtenaru); listener public void actionPerformed(ActionEvent e) { String jmeno = pole1.getText(); String prijmeni = pole2.getText(); listModel.addElement(jmeno +" "+ prijmeni); listCtenaru.setModel(listModel); pole1.setText(""); pole2.setText(""); pole1.requestFocus();

    Read the article

  • Limiting Row Selection in JTable

    - by Pat
    Is there an easy way to limit the total selection of rows in a JTable? I mean I'd like to allow the user to use shift and ctrl to select a maximum of X rows. If he clicks again on a row it would cancel out all the selections. Sort of how it currently behaves, but while limiting the total amount of selected rows. Here's my current implementation, I'm kind of clueless on how to limit the selection graphically. public class RoomsListView extends AbstractViewPanel { public RoomsListView(DefaultController controller) { this.controller = controller; initUI(); } private void initUI() { tableT = new JTable(RoomsModel.getInstance()); sorter = new TableRowSorter<RoomsModel>(RoomsModel.getInstance()); tableT.setRowSorter(sorter); tableT.setPreferredScrollableViewportSize(new Dimension(CUSTOM_TABLE_WIDTH, CUSTOM_TABLE_HEIGHT)); tableT.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { rowClickedPerformed(e); } }); } private void rowClickedPerformed(MouseEvent e) { } public void modelPropertyChange(PropertyChangeEvent evt) { } public JTable getTable() { return tableT; } private final int CUSTOM_TABLE_WIDTH = -1; private final int CUSTOM_TABLE_HEIGHT = 150; private JTable tableT; private DefaultController controller; private TableRowSorter<RoomsModel> sorter; }

    Read the article

  • Displaying data from linked tables in netbeans JTable

    - by Darc
    I have been writing in java for a few months now and have just started using netbeans. I have spent all day today trying to work out how to connect to an SQL database and display data from 2 tables (ie display the data from from a select statement with an inner join) in a JTable. I have tried using JPQL with the following statment SELECT j, cust.name FROM Job j JOIN j.jobnumber cust where the job table has a field called customer that references id in the customer table. This throws the exception: Caused by: Exception [TOPLINK-8029] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.EJBQLException Exception Description: Error compiling the query [SELECT j, cust.name FROM Job j JOIN j.jobnumber cust], line 1, column 11: invalid navigation expression [cust.name], cannot navigate expression [cust] of type [java.lang.Integer] inside a query. at oracle.toplink.essentials.exceptions.EJBQLException.invalidNavigation(EJBQLException.java:430) What am i doing wrong? Can anyone point me to some examples of how to make a linked table java application? I am still in the very early stages of development so a complete change is not out of the question if using a mysql database isnt the best way to go about things thanks

    Read the article

  • how can i display the database data to an jtable(dynamic) in the swings!

    - by harish0510
    we are using hibernate in business layer,but the task is, by using the jtable in swings to display the dynamic data(swings) from the database. code: Criteria criteria=session.createCriteria(User.class); //here user.class is pojo class in hibernate. List studentlist= criteria.list(); System.out.println("records"+studentlist); here the data is showing in hibernate console, but how to represent that data in the format of "jtable".

    Read the article

  • Switching Between Cards in a CardLayout using getParent()

    - by plutoisaplanet
    Hey everyone, I am writing an application where I am using the CardLayout to swap between two panels that are placed right on top of one another. There's a JPanel called Top, and it's layout is the CardLayout. Inside this JPanel is a JPanel called CMatch. Whenever the user clicks the submit button in the CMatch panel, I want a new JPanel added to Top that is custom built based on what the user types in, and it will be shown instead of the original CMatch panel. All of this done using the CardLayout. These are all different classes in different files, however (the panel Top with CardLayout, the panel CMatch that is inside the Top panel, and the custom built panel). So i tried using the following to add the new panel to the Top panel and then have it shown: (this code takes place in the CMatch class): private void submitButtionActionPerformed(ActionEvent e) { CardLayout cl = (CardLayout)(this.getParent().getLayout()); cl.addLayoutComponent(new CChoice(), "college_choices"); cl.show(this.getParent(), "college_choices"); } However, this didn't work. So i was wondering, what am I doing wrong? Any advice is greatly appreciated, thanks!

    Read the article

  • How do I remove an old JPanel and add a new one?

    - by Roman
    I would like to remove an old JPanel from the Window (JFrame) and add a new one. How should I do it? I tried the following: public static void showGUI() { JFrame frame = new JFrame("Colored Trails"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(partnerSelectionPanel); frame.setSize(600,400); frame.setVisible(true); } private static void updateGUI(final int i, final JLabel label, final JPanel partnerSelectionPanel) { SwingUtilities.invokeLater( new Runnable() { public void run() { label.setText(i + " seconds left."); } partnerSelectionPanel.setVisible(false); \\ <------------ } ); } So, my code update the "old" JPanel and them it makes the whole JPanel invisible. It was the idea. But it does not work. The compiler complains about the line indicated with "<------------". It writes: <identifier> expected, illegal start of type.

    Read the article

  • Synchronize JTextFields Values by PropertyChangeListener

    - by gt_ebuddy
    I want to copy the value of a jTextField - TXTFLD1 to another jTextField -TXTFLD2 when the value at TXTFLD1 changes. I choose propertychangelistener because i cannot detect when the value at TXTFLD1 is changed, Because it is changed by some external code which i cannot modify now. The test code is as follows : public class TxtFldSync extends JFrame { private JButton BTN1 = null; private JTextField TXTFLD1 = null; private JTextField TXTFLD2 = null; public static void main(String[] args) { TxtFldSync thisClass = new TxtFldSync(); thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); thisClass.setVisible(true); } public TxtFldSync() { super(); this.setSize(300, 200); BTN1 = new JButton(); BTN1.setBounds(new Rectangle(178, 38, 67, 17)); TXTFLD1 = new JTextField(); TXTFLD1.setBounds(new Rectangle(32, 42, 83, 20)); TXTFLD2 = new JTextField(); TXTFLD2.setBounds(new Rectangle(30, 78, 83, 20)); //listeners TXTFLD1.addPropertyChangeListener("value", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent arg0) { TXTFLD2.setText(TXTFLD1.getText()+"set by change listener"); //this doesnot work why ? } }); BTN1.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { TXTFLD1.setText("Action Performed"); //i what to set same value to TXTFLD2 using property change listener } }); this.setContentPane(new Container()); this.getContentPane().add(BTN1); this.getContentPane().add(TXTFLD1); this.getContentPane().add(TXTFLD2); } } Why the property change listener is not working. What are the other alternatives solution for this problem?

    Read the article

< Previous Page | 33 34 35 36 37 38 39 40 41 42 43 44  | Next Page >