Search Results

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

Page 20/63 | < Previous Page | 16 17 18 19 20 21 22 23 24 25 26 27  | Next Page >

  • [hibernate - jpa ] good practices and bad practices

    - by blow
    Hi all, i have some questions about interaction with hibernate. openSession or getCurrentSession (without jta, thread insted)? How mix session operations with swing gui? Is good have something like this in a javabean class? public void actionPerformed(ActionEvent event) { // session code } Can i add methods to my entities that contains hql queries or is a bad practice? For example: // This method is in an entity MyOtherEntity.java class public int getDuration(){ Session session=HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); int sum=(Integer)session.createQuery("select sum(e.duration) as duration from MyEntity as e where e.myOtherEntity.id=:id group by e.name"). .setLong("id", getId()); .uniqueResult(); return sum; } In alternative how can i do this in a better and elegant way? Thanks.

    Read the article

  • Scheduling Swingworker threads

    - by Simonw
    Hi, I have a 2 processes to perform in my swing application, one to fill a list, and one to do operations on each element on the list. I've just moved the 2 processes into Swingworker threads to stop the GUI locking up while the tasks are performed, and because I will need to do this set of operations to several lists, so concurrency wouldn't be a bad idea in the first place. However, when I just ran fillList.execute();doStuffToList.execute(); the doStuffToList thread to ran on the empty list (duh...). How do I tell the second process to wait until the first one is done? I suppose I could just nest the second process at the end of the first one, but i dunno, it seems like bad practice.

    Read the article

  • Check if thread is EDT is necessary?

    - by YuppieNetworking
    Hello, I have an UI implemented with Swing. One component does some work that may take some time, so I use SwingUtilities.invokeLater. However, I was reading some old code and found this in an ActionListener: if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater(new Runnable() { public void run() { // code X } }); } else { // code X } I thought that it made sense since it separates code X from the EDT. However, I found it error-prone since I have used it a couple of times and both times I forgot the else part. The question is: is the SwingUtilities.isEventDispatchThread() checking necessary? Or could I assume that I am not in the EDT and always use invokeLater? Thanks a lot.

    Read the article

  • How can I create a JTable where the first column is always in the JScrollPane viewport?

    - by voodoogiant
    What's the best way to set up a table in a JScrollPane such that the first column is always on the screen in the same position regardless of horizontal scrolling and overlaps columns that pass underneath? When the scrollbar is at the farthest left, the columns look normal, but as the user scrolls to the right, the secondary columns (2 and on) move underneath the first until the last column appears on the far right of the viewport? I found a sample taken from Eckstein's "Java Swing" book that sort of does this, but it doesn't allow resizing of the first column. I was thinking of some scheme where one JPanel held a horizontal struct and a table holding the secondary columns and another JPanel which floated over them (fixed regardless of scrolling). The struct would be to keep the viewport range constant as the first column floated around. Ideally I could do it with two tables using the same model, but I'm not sure if the whole idea is a naive solution.

    Read the article

  • JLabel with separate text and icon background colours

    - by emeraldjava
    Hey, I have a simple Jlabel element with text and icon setting the background changes the full label colour. I want to be able to only render the background colour on the text section of the label, ie - to have separate backgrounds/foregrounds for the icon and text. Selecting/deselecting the label will flip the colour behind the icon and text. Is this possible to do this by just extending JLabel, and if so which methods should i be looking to customise? My alternative idea is to create a panel with two separate label elements, one with an icon the other with text. It seems a bit messy, and before i start i'm wondering is there a smarter way of achieving this with Swing.

    Read the article

  • Partial match in MaskFormatter for jFormattedTextField

    - by Toto
    How do I set up the MaskFormatter and the JFormattedTextField in order to allow partial matches? For example: I want the user to be able to enter numbers with this mask "## ###### ####", so if the user enters '123456789123' the formatter changes it to '12 345678 9123'. However, I also want the user to be able to enter '12346578', be converted to '12 345678' and still be a valid value (so I can get it using jFormatedTextField1.getValue()) This is part of my code (most of it generated by Netbeans): private javax.swing.JFormattedTextField jFormattedTextField1; // ... try { jFormattedTextField1.setFormatterFactory(new DefaultFormatterFactory(new MaskFormatter("## ###### ####"))); } catch (java.text.ParseException ex) { ex.printStackTrace(); } I've tried setting the focusLostBehavior to PERSIST so the value is not cleard after exiting the jFormattedTextField1, but that way I get a null when using the calling jFormattedTextField1.getValue()

    Read the article

  • JComponent undock effect

    - by Christo Du Preez
    I'm trying to accomplish an undock effect for a custom Swing JComponent. By default the component is used inside a form along with other components. I want to be able to maximize this component to use the whole screen and then be able to dock it again. So far I've tested public void showDialog() { JFrame mainFrame = App.getApplication().getMainFrame(); JDialog dialog = new JDialog(mainFrame); dialog.setModal(true); dialog.setSize(800, 600); //Set to 80x660 for now dialog.add(this); //This is my JComponent dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); } This gives me desired effect but when closing the dialog my component doesn't receive events no more. How can I prevent this? Or is there perhaps a better way to accomplish this?

    Read the article

  • Having difficulty add a custom icon to a JFrame

    - by Oliver
    Hi, I have been trying to change the icon in the frame. I have virtually tried everything: The icon is 16x16 which is the right size ....doesn't work I've trying PNG,GIF and JPG formats none of them work. Tried different way of setting the icon....doesn't work. I've tried relative (local paths) e.g. "icon.gif" and absolute paths e.g. "c:\work\java\icon.gif" ...doesn't work Here is my code and see if you can figure it out Thanks Oli import javax.swing.*; public class androidDriver { public static void main(String[] args) throws IOException { JFrame f = new JFrame("Android Data Viewer"); f.setResizable(false); f.setSize(300,300); f.setLocationRelativeTo(null); f.setVisible(true); f.setIconImage(new ImageIcon("androidIcon2.gif").getImage()); } }

    Read the article

  • JAVA: How to use paint() method to update the previously drawn object?

    - by GamDroid
    How to use paint() such that when repaint() is called the previously drawn object should not get deleted when drawing the new object. That is the drawing area must get UPDATED only and not REDRAWN. In my code when one of many button is clicked, some aplhabet get displayed. I want to have functionality such that when other buttons are clicked the previously drawn alhabets must be present.Take is as if a string of alphabets getting created as the buttons are clicked. Im using Java Swing for coding. Some piece of my code: if(source == btnAlpha[i] ) bollyDraw.repaint(); //bollydraw is an object of a JPanel extended class having implemented the paintComponent(Graphics g) method In the paint() method: if (word[i] == key) { g.drawChars(word, i, 1, x, y); }

    Read the article

  • Read / write program in Java using JFileChooser

    - by Casper Marcussen
    Didn't want to bother people in here, but since I am under a time pressure, I am desperate to get help. My questions is how to link the file choosen from a JFileChooser to a file, and how to convert it to string being able to display and edit it in a TextArea. I have the GUI set up using swing, but the link between actionListener and the JFileChooser is not complete. Any help would be much appreciated. Code: http://pastebin.com/p3fb17Wi EDIT: I found this program, that does pretty much what i wanted to, but it does not allow me to save the actual file : http://www.java-forums.org/new-java/8856-how-get-content-text-file-write-jtextarea.html

    Read the article

  • DJ JWebBrowser: how to show but disable Address and Button bars?

    - by Nikolay Kuznetsov
    I am using chrriis.dj.nativeswing.swtimpl.components.JWebBrowser in my swing application to open web page. The page is going to show "Facebook Authentication" page and I want to prevent user from inputting some other URL other than I specify and also Forward and Back buttons should be visible but not has no affect. So following functions are applicable for my goal setButtonBarVisible(true); setLocationBarVisible(true); Once user completes the authentication I will handle the locationChanged event. @Override public void locationChanged(WebBrowserNavigationEvent arg0) { System.out.println("locationChanged!"); .... } }

    Read the article

  • Adding JTextField to a JPanel and showing them

    - by Davide Gualano
    I'm building a little app using Java and Swing in NetBeans. Using NetBeans design window, I created a JFrame with a JPanel inside. Now I want to dynamically add some jTextFields to the JPanel. I wrote something like that: Vector textFieldsVector = new Vector(); JTextField tf; int i = 0; while (i < 3) { tf = new JTextField(); textFieldVector.add(tf); myPanel.add(tf); //myPanel is the JPanel where I want to put the JTextFields i++; } myPanel.validate(); myPanel.repaint(); But nothing happens: when I run the app, the JFrame shows with the JPanel inside, but the JTextFields don't. I'm a total newbie in writing graphical Java apps, so I'm surely missing something very simple, but I can't see what.

    Read the article

  • "Unsupported Image Type" exception in only few images...

    - by Nitz
    In my java-swing project. I have one frame in which user can drop the images and save that images in database. Now this work perfectly but their are some images which is not showing. This are images Image 1 , Images 2 which is not supporting .. this are some images which are not reading... and its showing me exception, like javax.imageio.IIOException: Unsupported Image Type Can i check that, is the image which user had dropped is supported or not? And can i convert that file which is not supported into supported file in java?

    Read the article

  • How do I detect if a display is in High Contrast mode?

    - by banjollity
    I'm testing my company's established Swing application for accessibility issues. With high contrast mode enabled on my PC certain parts of this application are rendered properly (white-on-black) and some incorrectly (black-on-white). The bits that are correct are the native components (JButton, JLabel and whatnot) and third party components from the likes of JIDE. The incorrect bits are custom components and renderers developed in-house without consideration for high-contrast mode. Clearly it's possible to detect when high-contrast mode is enabled. How do I do this?

    Read the article

  • Visual Editor vs Manual code

    - by Albinoswordfish
    I'm not sure how it is using other frameworks but this questions is strictly regarding Java swing. Is it better to use a Visual Editor to place objects or to manually code the placement of the objects onto the frame (Layout managers or null layouts)? From my experience I've had a lot of trouble using Visual editors when it comes to different screen resolutions or changing the window size. Using manual code to place objects I've found that my GUIs behave a lot better with regard to the screen size issue. However when I want to change a small part of my GUI it takes a lot more work compared to using a visual editor Just wondering what people's thoughts were on this?

    Read the article

  • Java appliction design question

    - by ring bearer
    Hi I have a hobby project, which is basically to maintain 'todo' tasks in the way I like. One task can be described as: public class TodoItem { private String subject; private Date dueBy; private Date startBy; private Priority priority; private String category; private Status status; private String notes; } as you can imagine I would have 1000 todo items at a given time. What is the best strategy to store a todo item? (currently on an XML file) such that all the items are loaded quickly up on app start up(the application shows kind of a dashboard of all the items at start up) What is the best way to design its back-end so that it can be ported to android/or a J2ME based phone Currently this is done using java swing. What should be the concerns so that it works efficiently on a device where memory is limited? Thanks!

    Read the article

  • login form whith java/sqlite

    - by tuxou
    hi I would like to create a login form for my application with the possibility to add or remove users for an sqlite database, i have created the table users(nam, pass) but i can't unclud it in my login form, it someone could help me this is my login code: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class login extends JFrame { // Variables declaration private JLabel jLabel1; private JLabel jLabel2; private JTextField jTextField1; private JPasswordField jPasswordField1; private JButton jButton1; private JPanel contentPane; // End of variables declaration public login() { super(); create(); this.setVisible(true); } private void create() { jLabel1 = new JLabel(); jLabel2 = new JLabel(); jTextField1 = new JTextField(); jPasswordField1 = new JPasswordField(); jButton1 = new JButton(); contentPane = (JPanel)this.getContentPane(); // // jLabel1 // jLabel1.setHorizontalAlignment(SwingConstants.LEFT); jLabel1.setForeground(new Color(0, 0, 255)); jLabel1.setText("username:"); // // jLabel2 // jLabel2.setHorizontalAlignment(SwingConstants.LEFT); jLabel2.setForeground(new Color(0, 0, 255)); jLabel2.setText("password:"); // // jTextField1 // jTextField1.setForeground(new Color(0, 0, 255)); jTextField1.setSelectedTextColor(new Color(0, 0, 255)); jTextField1.setToolTipText("Enter your username"); jTextField1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jTextField1_actionPerformed(e); } }); // // jPasswordField1 // jPasswordField1.setForeground(new Color(0, 0, 255)); jPasswordField1.setToolTipText("Enter your password"); jPasswordField1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jPasswordField1_actionPerformed(e); } }); // // jButton1 // jButton1.setBackground(new Color(204, 204, 204)); jButton1.setForeground(new Color(0, 0, 255)); jButton1.setText("Login"); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); // // contentPane // contentPane.setLayout(null); contentPane.setBorder(BorderFactory.createEtchedBorder()); contentPane.setBackground(new Color(204, 204, 204)); addComponent(contentPane, jLabel1, 5,10,106,18); addComponent(contentPane, jLabel2, 5,47,97,18); addComponent(contentPane, jTextField1, 110,10,183,22); addComponent(contentPane, jPasswordField1, 110,45,183,22); addComponent(contentPane, jButton1, 150,75,83,28); // // login // this.setTitle("Login To Members Area"); this.setLocation(new Point(76, 182)); this.setSize(new Dimension(335, 141)); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); this.setResizable(false); } /** Add Component Without a Layout Manager (Absolute Positioning) */ private void addComponent(Container container,Component c,int x,int y,int width,int height) { c.setBounds(x,y,width,height); container.add(c); } private void jTextField1_actionPerformed(ActionEvent e) { } private void jPasswordField1_actionPerformed(ActionEvent e) { } private void jButton1_actionPerformed(ActionEvent e) { System.out.println("\njButton1_actionPerformed(ActionEvent e) called."); String username = new String(jTextField1.getText()); String password = new String(jPasswordField1.getText()); if(username.equals("") || password.equals("")) // If password and username is empty Do this { jButton1.setEnabled(false); JLabel errorFields = new JLabel("You must enter a username and password to login."); JOptionPane.showMessageDialog(null,errorFields); jTextField1.setText(""); jPasswordField1.setText(""); jButton1.setEnabled(true); this.setVisible(true); } else { JLabel optionLabel = new JLabel("You entered "+username+" as your username. Is this correct?"); int confirm =JOptionPane.showConfirmDialog(null,optionLabel); switch(confirm){ // Switch Case case JOptionPane.YES_OPTION: // Attempt to Login user jButton1.setEnabled(false); // Set button enable to false to prevent 2 login attempts break; case JOptionPane.NO_OPTION: // No Case.(Go back. Set text to 0) jButton1.setEnabled(false); jTextField1.setText(""); jPasswordField1.setText(""); jButton1.setEnabled(true); break; case JOptionPane.CANCEL_OPTION: // Cancel Case.(Go back. Set text to 0) jButton1.setEnabled(false); jTextField1.setText(""); jPasswordField1.setText(""); jButton1.setEnabled(true); break; } // End Switch Case } } public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception ex) { System.out.println("Failed loading L&F: "); System.out.println(ex); } new login(); }; }

    Read the article

  • File is not Writing using FileOutputStream in java

    - by Krishna
    I have Java Desktop Swing application in which i am trying to write xml file but its not writing data into file here my code is FileOutputStream fileOutputStream = new FileOutputStream(input_file); SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); SOAPMessage soapResponse = soapConnection.call(soapcall, url); String str = WebServiceDAO.soapMessageToString(soapResponse); System.err.println("String*****" + str); fileOutputStream.write(str.getBytes()); fileOutputStream.close(); here i am getting data but its not writing in file what could be the prob?

    Read the article

  • Progress bar increment by 1 every 100th of second

    - by Matthew De'Loughry
    I'm trying to get a JProgressBar to increment by 1 every 100th of a second, and at the moment I'm using Thread.sleep(100) inside a while statement like so: try { while (i<=100){ doTime(); } } catch (InterruptedException ex) { Logger.getLogger(SplashScreen.class.getName()).log(Level.SEVERE, null, ex); } public void doTime() throws InterruptedException{ jLabel1.setText("sleeping"); Thread.sleep(100); jLabel1.setText("start"); i++; pb.setValue(i); pb.repaint(); } and If I debug by doing a System.out.println it displays in real time but the swing GUI freezes until it drops out of the while loop can anyone help? thanks matt

    Read the article

  • How can I clip strings in Java2D and add ... in the end?

    - by Jonas
    I'm trying to print Invoices in a Java Swing applications. I do that by extending Printable and implement the method public int print(Graphics g, PageFormat pf, int page). I would like to draw strings in columns, and when the string is to long I want to clip it and let it end with "...". How can I measure the string and clip it at the right position? Some of my code: Font headline = new Font("Times New Roman", Font.BOLD, 14); g2d.setFont(headline); FontMetrics metrics = g2d.getFontMetrics(headline); g2d.drawString(myString, 0, 20); I.e How can I limit myString to be max 120px? I could use metrics.stringWidth(myString), but I don't get the position where I have to clip the string. Expected results could be: A longer string that exc... A shorter string. Another long string, but OK

    Read the article

  • Building a Monopoly Board with GridBagLayout

    - by Oetzi
    I have been building a Java version of Monopoly in my spare time and am having some trouble understanding layouts etc for Swing. Each one of my spaces on the board is a essentially a custom JButton and I have been trying to lay them around the edge of a frame (like on the monopoly board itself). I can't seem to find a useful explanation of how the layout system works and so am having trouble do so. Could someone please give me an example of how they would lay the buttons around the edge of the frame? Should I be using a different layout?

    Read the article

  • Add a listener inside or outside get method

    - by James P.
    I'm learning Swing and have composed an interface using a series of get methods to add components. Is it a good practise to add a Listener inside a get method as follows? I'd like to make things as decoupled as possible. private JButton getConnectButton() { if (connectButton == null) { connectButton = new JButton(); connectButton.setText("Connect"); connectButton.setSize(new Dimension(81, 16)); connectButton.setLocation(new Point(410, 5)); connectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // actionPerformed code goes here } }); } return connectButton; }

    Read the article

  • calling invokeAndWait from the EDT

    - by Aly
    Hi, I have a problem following from my previous problem. I also have the code SwingUtillities.invokeAndWait somewhere else in the code base, but when I remove this the gui does not refresh. If I dont remove it the error I get is: Exception in thread "AWT-EventQueue-0" java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread at java.awt.EventQueue.invokeAndWait(Unknown Source) at javax.swing.SwingUtilities.invokeAndWait(Unknown Source) at game.player.humanplayer.model.HumanPlayer.act(HumanPlayer.java:69) The code in HumanPlayer.act is: public Action act(final Action[] availiableActions) { try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { gui.update(availiableActions); } }); } catch (InterruptedException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } synchronized(performedAction){ while(!hasPerformedAction()){ try { performedAction.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } setPerformedAction(false); } return getActionPerfomed(); }

    Read the article

  • Top tips for designing GUIs?

    - by oxbow_lakes
    A while back I read (before I lost it) a great book called GUI Bloopers which was full of examples of bad GUI design but also full of useful tidbits like Don't call something a Dialog one minute and a Popup the next. What top tips would you give for designing/documenting a GUI? It would be particularly useful to hear about widgets you designed to cram readable information into as little screen real-estate as possible. I'm going to roll this off with one of my own: avoid trees (e.g. Swing's JTree) unless you really can't avoid it, or have a unbounded hierarchy of stuff. I have found that users don't find them intuitive and they are hard to navigate and filter. PS. I think this question differs from this one as I'm asking for generalist tips

    Read the article

  • How I can get output from 1st frame textfield input text to 2nd frame textArea

    - by soulgreen
    Here is my 1st frame - I want went I input text in textfield example name then click button report will display output to 2nd frame using textArea... please help me import java.awt.; import java.awt.event.; import javax.swing.; import javax.swing.border.; public class Order extends JFrame implements ActionListener { private JPanel pInfo,pN, pIC, pDate,Blank,pBlank, button, pTotal; private JLabel nameL,icL,DateL; private JTextField nameTF, icTF; private JFormattedTextField DateTF; private JButton calB,clearB,exitB,reportB; public Order() { Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.setBackground(Color.gray); pInfo = new JPanel(); pN = new JPanel(); pIC = new JPanel(); pDate = new JPanel(); nameTF = new JTextField(30); icTF = new JTextField(30); DateTF = new JFormattedTextField(java.util.Calendar.getInstance().getTime()); DateTF.setEditable (false); DateTF.addActionListener(this); nameL = new JLabel(" NAME : ",SwingConstants.RIGHT); icL = new JLabel(" IC : ",SwingConstants.RIGHT); DateL = new JLabel(" DATE :",SwingConstants.RIGHT); pInfo.setLayout(new GridLayout(10,2,5,5)); pInfo.setBorder(BorderFactory.createTitledBorder (BorderFactory.createEtchedBorder(),"ORDER")); pN.add(nameL); pN.add(nameTF); pIC.add(icL); pIC.add(icTF); pDate.add(DateL); pDate.add(DateTF); pInfo.add(pN); pInfo.add(pIC); pInfo.add(pDate); pInfo.setBackground(Color.GRAY); pN.setBackground(Color.gray); pIC.setBackground(Color.gray); pDate.setBackground(Color.gray); nameL.setForeground(Color.black); icL.setForeground(Color.black); DateL.setForeground(Color.black); nameTF.setBackground(Color.pink); icTF.setBackground(Color.pink); DateTF.setBackground(Color.pink); contentPane.add(pInfo,BorderLayout.CENTER); Blank = new JPanel(); pBlank = new JPanel(); button = new JPanel(); calB = new JButton("CALCULATE"); calB.setToolTipText("Click to calculate"); clearB = new JButton("RESET"); clearB.setToolTipText("Click to clear"); reportB = new JButton ("REPORT"); reportB.setToolTipText ("Click to print"); exitB = new JButton("EXIT"); exitB.setToolTipText("Click to exit"); Blank.setLayout(new GridLayout(2,2)); Blank.setBorder(BorderFactory.createTitledBorder (BorderFactory.createEtchedBorder(),"")); button.setLayout(new GridLayout(1,4)); button.add(calB,BorderLayout.WEST); button.add(clearB,BorderLayout.CENTER); button.add(reportB,BorderLayout.CENTER); button.add(exitB,BorderLayout.EAST); Blank.add(pBlank); Blank.add(button); contentPane.add(Blank,BorderLayout.SOUTH); Blank.setBackground(Color.gray); pBlank.setBackground(Color.gray); calB.setForeground(Color.black); clearB.setForeground(Color.black); reportB.setForeground(Color.black); exitB.setForeground(Color.black); calB.setBackground(Color.pink); clearB.setBackground(Color.pink); reportB.setBackground(Color.pink); exitB.setBackground(Color.pink); calB.addActionListener(this); clearB.addActionListener(this); reportB.addActionListener(this); exitB.addActionListener(this); } public void actionPerformed(ActionEvent p) { if (p.getSource() == calB) { } else if (p.getSource() == clearB) { } else if (p.getSource () == reportB) { } else if (p.getSource() == exitB) { } } public static void main (String [] args) { Order frame = new Order(); frame.setTitle("Order"); frame.setSize(500,500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); frame.setVisible(true); frame.setLocationRelativeTo(null);//center the frame } }

    Read the article

< Previous Page | 16 17 18 19 20 21 22 23 24 25 26 27  | Next Page >