Search Results

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

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

  • How to implement button in a vector

    - by user1880497
    In my table. I want to put some buttons into each row that I can press. But I do not know how to do it public static DefaultTableModel buildTableModel(ResultSet rs) throws SQLException { java.sql.ResultSetMetaData metaData = rs.getMetaData(); // names of columns Vector<String> columnNames = new Vector<String>(); int columnCount = metaData.getColumnCount(); for (int column = 1; column <= columnCount; column++) { columnNames.add(metaData.getColumnName(column)); } // data of the table Vector<Vector<Object>> data = new Vector<Vector<Object>>(); while (rs.next()) { Vector<Object> vector = new Vector<Object>(); for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) { vector.add(rs.getObject(columnIndex)); } data.add(vector); } return new DefaultTableModel(data, columnNames); }

    Read the article

  • Need to have JProgress bar to measure progress when copying directories and files

    - by user1815823
    I have the below code to copy directories and files but not sure where to measure the progress. Can someone help as to where can I measure how much has been copied and show it in the JProgress bar public static void copy(File src, File dest) throws IOException{ if(src.isDirectory()){ if(!dest.exists()){ //checking whether destination directory exisits dest.mkdir(); System.out.println("Directory copied from " + src + " to " + dest); } String files[] = src.list(); for (String file : files) { File srcFile = new File(src, file); File destFile = new File(dest, file); copyFolder(srcFile,destFile); } }else{ InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int length; while ((length = in.read(buffer)) > 0){ out.write(buffer, 0, length); } in.close(); out.close(); System.out.println("File copied from " + src + " to " + dest); }

    Read the article

  • Setting the size of a ContentPane (inside of a JFrame)

    - by Jim
    Hello, I want to set the size of a JFrame such that the contentPane is the desired size. JFrame.setSize() doesn't take the window decorations into account, so the contentPane is slightly too small. The size of the window decorations are platform and theme specific, so it's bad news to try to manually account for them. JFrame.getContentPane().setSize() fails because it's managed. Ideas? Thanks!

    Read the article

  • Why do people run Java GUI's on the Event Queue

    - by asmo
    In Java, to create and show a new JFrame, I simply do this: public static void main(String[] args) { new JFrame().setVisible(true); } However, I have seen many people doing it like this: public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { new JFrame().setVisible(true); } }); } Why? Are there any advantages?

    Read the article

  • strange bug - how to pause a java program?

    - by TerraNova993
    I'm trying to: display a text in a jLabel, wait for two seconds, then write a new text in the jLabel this should be simple, but I get a strange bug: the first text is never written, the application just waits for 2 seconds and then displays the final text. here is the example code: private void testButtonActionPerformed(java.awt.event.ActionEvent evt) { displayLabel.setText("Clicked!"); // first method with System timer /* long t0= System.currentTimeMillis(); long t1= System.currentTimeMillis(); do{ t1 = System.currentTimeMillis(); } while ((t1 - t0) < (2000)); */ // second method with thread.sleep() try { Thread.currentThread().sleep(2000); } catch (InterruptedException e) {} displayLabel.setText("STOP"); } with this code, the text "Clicked!" is never displayed. I just get a 2 seconds - pause and then the "STOP" text. I tried to use System timer with a loop, or Thread.sleep(), but both methods give the same result.

    Read the article

  • change JPanel after clicking on a button

    - by Fixus
    I'm building simple GUI for my app. I have couple of JPanels. I want to display them depending on action that was performed by clicking on a JButton. How can I disable one JPanel and enable another one ? Couple of details. I have a class with JFrame where I'm building starting gui. Where I have buttons and some text. Clicking on one of the buttons should change the view in this JFrame my button definition JButton btnStart = new JButton("Start"); btnStart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); btnStart.setBounds(10, 11, 110, 23); contentPane.add(btnStart);

    Read the article

  • Background image JFrame with content

    - by Petr Safar
    I have a JFrame with BorderLayout, there are panels on all sides (North, East ,...). In the panels there are labels and buttons mostly. Now I want the frame to have a background image, some research told me that i had to change the content pane of my frame. When I try this however, the content gets put in the background and isn't visible. Also, I don't know how to resize the image if the frame is resized. Is there an easy fix for this or will I have to rework most of my code?

    Read the article

  • Java JCheckBox ArrayList help needed

    - by user2929626
    I'm new to Java and struggling with something which I'm sure must have a simple answer but I can't seem to find it. I have an array of checkbox objects defined as: ArrayList<JCheckBox> checkBoxList A JPanel is created with a grid layout and the checkboxes are added to the JPanel and the ArrayList: for (int i = 0; i < 256; i++) { JCheckBox c = new JCheckBox(); c.setSelected(false); checkBoxList.add(c); mainPanel.add(c); } Yes, there are 256 checkboxes! The panel is added to a JFrame and eventually the GUI is displayed. The user can select any combination of the 256 checkboxes. My class implements Serializable and this ArrayList of checkboxes can be saved and restored using 'Save' and 'Load' GUI buttons. My code to load the saved object is as below: public class LoadListener implements ActionListener { public void actionPerformed(ActionEvent a) { try { // Prompt the user for a load file JFileChooser fileLoad = new JFileChooser(); fileLoad.showOpenDialog(mainFrame); // Create a object/file input stream linking to the selected file ObjectInputStream is = new ObjectInputStream(new FileInputStream(fileLoad.getSelectedFile())); // Read the checkBox array list checkBoxList = (ArrayList<JCheckBox>) is.readObject(); is.close(); } catch (Exception ex) { ex.printStackTrace(); } } On loading the ArrayList object, the values of the checkboxes are correctly populated, however I want to update the checkboxes on the GUI to reflect this. Is there an easy way to do this? I assumed as the array of checkboxes had the correct values that I could just repaint the panel / frame but this doesn't work. I'd like to understand why - does my loaded array of checkbox objects no longer reflect the checkbox objects on the GUI? Any help would be much appreciated. Thanks!

    Read the article

  • pass Value from class to JFrame

    - by MYE
    Hello everybody! i have problem between pass value from Class to another JFrame my code write follow MVC Model. Therefore i have 1 class is controller , one jframe is view and 1 class is model. i have some handle process on controller to get value on it and i want this value to jframe but not pass by constructor . How can i pass value from class to jframe and when value be pass jframe will use it to handle. Ex: public class A{ private String str; public A(){ } public void handle(){ ViewFrame v = new ViewFrame(); v.setVisible(true); v.pack(). v.setSize(330,600); str = "Hello World"; //init value here v.getString(str);// pass value to jframe here. } } ======================= public class ViewFrame extends JFrame{ private String str; public ViewFrame (){ System.out.println(str); } public String getString(String str){ return this.str = str; } } but it return null??

    Read the article

  • Is it possible to draw simultaneously on a panel?

    - by swift
    I have to develop a whiteboard application in which both the local user and the remote user should be able to draw simultaneously, is this possible? If possible then any logic? I have already developed a code but in which i am not able to do this, when the remote user starts drawing the shape which i am drawing is being replaced by his shape and co-ordinates. This problem is only when both draw simultaneously. any idea guys?

    Read the article

  • Secure Desktop Mode effect for java application

    - by Aiden Strydom
    Does anyone now how to achieve a "Secure-Desktop Mode" (effect) such as one gets from the Windows Vista/7 UAC consent-blocks? I assume it is some function which will remove pixels here-and-there (and possibly graying them) and then finally drawing that to screen... I would like to apply it to my application to keep the user from doing anything until the another user connects to the system (but that is besides the point) I would really appreciate the advise. Kind regards A EDIT: i was really only looking for this graphicsFX.setColor(new Color(0, 0, 0, 0.8f)); graphicsFX.fillRect(0, 0, 800, 600); the defering of input i can do quite well... Thanks for all....

    Read the article

  • Using JLists and ListModels

    - by devoured elysium
    I have defined a DirectoryListModel class that extends the AbstractListModel class from the Java Api. Internally, I have a list of File objects. I have defined the getElementAt(int index) method as: @Override public Object getElementAt(int index) { return directoryElements.get(index) } The problem is that when I try to run my JList with my DirectoryListModel, it is going to show up the full paths of files instead of just the filenames. I could change this code to: @Override public Object getElementAt(int index) { return directoryElements.get(index).getName(); } and it'd work wonders, but the problem is that in the onclick event I'll want to have the File objects so I can do some checking with them (check if they're directories, etc). If I make getElementAt() return a String, I'm losing that possibility, thus I'd like to konw if there is a way I can format my File objects before the JList shows them in my window. Thanks

    Read the article

  • About NullPointer Exception in Arraylist

    - by user2234456
    List<PrcSubList> listSl = new ArrayList<PrcSubList>(); if (listSl == null || listSl.size() == 0) { PrcSubList subListAdd=coreService.addSubListByAddAlert(childSub); System.out.println("sublist after insert db :" + subListAdd.getName()); listSl.add(subListAdd); System.out.println(listSl.size() +" sublist after insert list:" + listSl.get(0).getName()); } Ouput with first System.out.println("sublist after insert db :" + subListAdd.getName()); sublist after insert db :SYSTEM_ALERT_12312313 Problem But i have NullPointerException with 2nd System.out.println(listSl.size() +" sublist after insert list:" + listSl.get(0).getName()); Can you help me!

    Read the article

  • How to use CellRenderer for GregorianCalendar?

    - by HansDampf
    So I have been trying to use the example from Tutorial and change it so it fits my program. The getColumnValue method returns the object that holds the information that is supposed to be displayed. Is this the way to go or should it rather return the actual String to be displayed. I guess not because that way I would mix the presentation with the data, which I was trying to avoid. public class IssueTableFormat implements TableFormat<Appointment> { public int getColumnCount() { return 6; } public String getColumnName(int column) { if(column == 0) return "Datum"; else if(column == 1) return "Uhrzeit"; else if(column == 2) return "Nummer"; else if(column == 3) return "Name"; else if(column == 4) return "letzte Aktion"; else if(column == 5) return "Kommentar"; throw new IllegalStateException(); } public Object getColumnValue(Appointment issue, int column) { if(column == 0) return issue.getDate(); else if(column == 1) return issue.getDate(); else if(column == 2) return issue.getSample(); else if(column == 3) return issue.getSample(); else if(column == 4) return issue.getHistory(); else if(column == 5) return issue.getComment(); throw new IllegalStateException(); } } The column 0 and 1 contain a GregorianCalendar object, but I want column 0 to show the date and 1 to show the time. So I know using cellRenderers can help here. This is what I tried. public class DateRenderer extends DefaultTableCellRenderer { public DateRenderer() { super(); } public void setValue(Object value) { GregorianCalendar g =(GregorianCalendar) value; value=g.get(GregorianCalendar.HOUR); } } But the cell doesnt show anything, what is wrong here?

    Read the article

  • GridBagConstraints weightx and weighty values

    - by xdevel2000
    In many books weightx and weighty values are expressed in different ways: some says 0.0 to 1.0 other says 0 to 100 other say until 1000 I'm a lot confused. In the API these variables are double types so I think the first is correct but what does it meaning a value of 0.4 or 0.7? are percentage values, point values? relative of what?

    Read the article

  • How do I create a "jumping" circle in Java GUI?

    - by Roman
    I would like to have a red filled circle at some place in my window. After the click on the circle, the circle should jump from the original place to a new one (disappear from the old place and appear on the new one). What would be the best way to do it? I also would like to know how to draw a filled circle in Java. Are there any simple tools to do it? Or may be the easiest way is to use an image created by some other software?

    Read the article

  • How can I close a JFrame by click on a button?

    - by Roman
    I would like to have a button in my window such that if I click it (button) the window is closed. I found out that I can close a window in the following way: referenceToTheFrame.hide(); //hides the frame from view refToTheFrame.dispose(); //disposes the frame from memory But if I do this way, compiler complains: Note: myProgram.java uses or overrides a deprecated API Note: Recompile with -Xlint:deprication for details. Do I do something unsafe?

    Read the article

  • Best practice for an application with GUI

    - by chronosphenomena
    Hi, I'm about to start an application which will have both console and GUI interfaces. What I wan't to achieve is COMPLETE decoupling of application logic from interface. In future, I may also add web interface, and I don't want to change anything in my application. Is there a good example (perhaps some open source project) where I can learn how this should be done properly.... also I'd appreciate advices/guidelines on how to do this. Thanks

    Read the article

  • Is it the most common case?

    - by Knowing me knowing you
    Why when I click on the x button to close the window in a Java application only the window dissapears and the applicaton is still running. I've read so many times that java designers tried to cater Java behaviour for the most common needs of programmers and save they precious time and so on and so on. What's more common case than closing app when I click on a X button?

    Read the article

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