Search Results

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

Page 25/63 | < Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >

  • Maintaing JTextArea scroll position

    - by Sami
    I have a JScrollPane with a JTextArea set as its view port. I update the (multi line) text shown on the JTextArea continously about once a second. Each time the text updates, JScrollPane goes all the way to the bottom of the text. Instead, I'd like to figure out the line number that is currently shown as the first line in the original text, and have that line be the first line shown when the text has been updated (or if the new text doesn't have that many lines, then scroll all the way to the bottom). My first attempt of doing this was to get the current caret position, figure the line based on that, and then set the text area to show that line: int currentPos = textArea.getCaretPosition(); int currentLine = 0; try { for(int i = 0; i < textArea.getLineCount(); i++) { if((currentPos >= textArea.getLineStartOffset(i)) && (currentPos < gameStateTextArea.getLineEndOffset(i))) { currentLine = i; break; } } } catch(Exception e) { } textArea.setText(text); int newLine = Math.min(currentLine, textArea.getLineCount()); int newOffset = 0; try { newOffset = textArea.getLineStartOffset(newLine); } catch(Exception e) { } textArea.setCaretPosition(newOffset); This was almost acceptable for my needs, but requires the user to click inside the text area to change the caret position, so that the scrolling will maintain state (which isn't nice). How would I do this using the (vertical) scroll position instead ?

    Read the article

  • while loop ignore the event listener

    - by Tamer
    so when i run this code to try to change the background the GUI crashes and gets stuck in a infinite while loop ignoring the event listeners. here is the code: `private Panel getPanel1() { if (panel1 == null) { panel1 = new Panel(); panel1.setLayout(new GridBagLayout()); while(frame.isVisible()){ panel1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent e) { frame.setVisible(false); } }); int r = (int) (Math.random()*255); int g = (int) (Math.random()*255); int b = (int) (Math.random()*255); Color c = new Color(r, g, b); panel1.setBackground(c); try { Thread.sleep(4000); } catch (InterruptedException e1) { e1.printStackTrace(); } panel1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent e) { /*panel1.setVisible(false); frame.setVisible(false);*/ System.exit(0); } }); } } return panel1; }` instead of exiting the loop of terminating the program or event changing the background it just displays the panel and does nothing else and i have to force it to quit. what should i do?

    Read the article

  • How to set a Transparent Background of JPanel

    - by Imran
    Hi, I need to know if a JPanel`s bacground can be set to Transparent? My frame is has two Jpanels Image Panel and Feature Panel, Feature Panel is overlapping Image Panel, the Image Panel is working as a background and it is loading image from a remote Url, now I want to draw shaps on Feature Panel , but now Image Panel cannot be seen due to Feature Panel's background color. I need to make Feature Panel background transparent while still drawing its shapes and i want Image Panel to be visible since it is doing tiling and cache function of images. I need to seperate the image drawing and shape drawing thats why I`m using two jPanels! is there anyway the overlapping Jpanel have a transparent background? thanks

    Read the article

  • Checkboxes and Radio Buttons Together in a JTree

    - by Thunderforge
    I'd like to create a JTree that more or less has the following structure (with a hidden root node) [No Option] Main Dish [Radio Button] Steak [Radio Button] Fish [Radio Button] Filet Mignon [Checkbox] Side Dish [Checkbox] Mashed Potatoes [Checkbox] Green Beans [Checkbox] Mixed Vegetables [Checkbox] Dessert [Radio Button] Ice Cream [Radio Button] Pudding [Radio Button] Cake Basically, at least one main dish (but no more than one) can be chosen, any number of side dishes can be chosen (or none, if the "Side Dish" checkbox is unchecked), and only one dessert can be chosen (or none, if the "Dessert" checkbox is unchecked). This article describes how to create a tree that uses JCheckboxes (as I'd like to use for the Side Dish and Dessert sections) by creating a custom Renderer and page 3 of the same article describes how to use Radio buttons (as I'd like to use for the Main Course) section. But it doesn't describe how to mix them up within the same JTree. Is it possible to create a structure like this? And if so, how?

    Read the article

  • Dispatch MouseEvent

    - by shay
    there is a way to Dispatch MouseEvent , same as dispatchKeyEvent using the KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(listener); that happens before the event transferred to the component ? i know i have 2 options 1) add mouse event to all compoenents recursive 2) use a transparent glasspane dose java support this , or i have to use the one of the options above thank you

    Read the article

  • Background image in a JFrame.

    - by thepandaatemyface
    Hi, This question has been asked a lot but everywhere the answers fall short. I can get a JFrame to display a background image just fine by extending JPanel and overriding paintComponent, like so: class BackgroundPanel extends JPanel { private ImageIcon imageIcon; public BackgroundPanel() { this.imageIcon = Icons.getIcon("foo"); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(imageIcon.getImage(), 0,0,imageIcon.getIconWidth(),imageIcon.getIconHeight(),this); } } But now, how do you add a component on top of that background? When I go JFrame w = new JFrame() ; Container cp = w.getContentPane(); cp.setLayout(null); BackgroundPanel bg = new BackgroundPanel(); cp.add(bg); JPanel b = new JPanel(); b.setSize(new Dimension(30, 40)); b.setBackground(Color.red); cp.add(b); w.pack() w.setVisible(true) It shows the little red square (or any other component) and not the background, but when I remove cp.setLayout(null);, the background shows up but not my other component. I'm guessing this has something to do with the paintComponent not being called by the null LayoutManager, but I'm not at all familiar with how LayoutManagers work (this is a project for college and the assignment specifically says not to use a LayoutManager) When i make the image the background has to display null (and so, transparant (??)) the red square shows up so it might be that the background is actually above my other components) Does anyone anyone have any ideas? Thanks

    Read the article

  • Add transparent JPanel upon AWT Component to paint on

    - by Gambrinus
    Hi, I've got a Problem: In my Java application I've got an AWT Component (cannot change that one) that streams and shows an avi-file. Now I want to draw upon this movie and thought about putting a transparent JPanel above it and draw on that one. This does not work since I either see the avi-stream or the drawn lines but not both. I read somewhere that AWT does not support transparency of components - but the panel is a JPanel which is able to do so. Can someone please help me with this one - thanks in advance.

    Read the article

  • How to solve JAVA menubar, layout and panel problem ?

    - by Berkay
    i'm not a java guy however i start implementing some security tools with java, in these days i'm creating a gui for my security tools : Here is the how my Gui looks: menuBar = new JMenuBar(); // construct menu bar // hash functions fileMenu = new JMenu("HASH FUNCTIONS"); // define file menu fileMenu.setMnemonic('H'); // shortcut hashes = new JMenuItem("Md5&Sha1"); // define file menu options hashes.setMnemonic('M'); hashes.addActionListener(this); fileMenu.add(hashes); menuBar.add(fileMenu); // add file menu to menu bar // symmetric encryption asMenu = new JMenu("SYMMETRIC ENCRYPTION"); // define format menu asMenu.setMnemonic('S'); // shortcut desItem = new JMenuItem("DES"); // define format menu options desItem.setMnemonic('D'); desItem.addActionListener(this); asMenu.add(desItem); ... ... menuBar.add(helpMenu); // add help menu to menu bar setJMenuBar(menuBar); // put menu bar on application textColor = Color.RED; when from the Menu desitem is selected, desvar is just for not showing the panel multiple times, it calls Panels () else if(e.getSource() == desItem && desvar ==1 ) { // make other panels unvisible. if(hashvar!=1) MyPanel.setVisible(false);//hash functions if(rsavar!=1) MyPanel3.setVisible(false);//rsa function if (dhvar!=1) MyPanel4.setVisible(false);//dh diffie hellman hashvar=1; rsavar=1; dhvar=1; ++desvar; desPanel=true; Panels(); } and in Panels() Method: if (hashPanel){ MyPanel.add("West",radioSHA1); MyPanel.add("West",radioMD5); MyPanel.add("Center", inputField); MyPanel.add("East",SubmitButton); MyPanel.add("South",resultHash); add(MyPanel); validate(); hashPanel=false; } i have many panels for example : -hash functions=mypanel1 , des=mypanel2, rsa functions= mypanel3 , dh= mypanel4 However in may other panals such as rsa function: i have to use some layout properties of the java:in this panel i selected to use gridbaglayout if (dhPanel){ System.out.println("rsa panel burda misin"); MyPanel3.add(pqLabel); MyPanel3.add(pLabel); MyPanel3.add(pTextArea); MyPanel3.add(qLabel); ... ... add(MyPanel3); generate_pqButton.addActionListener(this); calculate_nButton.addActionListener(this); ... ... GridBagLayout layout = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); setLayout(layout); // x, y, w, h, wx, wy gbc.fill = GridBagConstraints.NONE; add (bit_length_label, gbc, 0, 0, 1, 1, 0, 10); add (p, gbc, 0, 1, 1, 1, 0, 10); add (g, gbc, 0, 2, 1, 1, 0, 10); add (a, gbc, 1, 3, 1, 1, 100, 10); add (x, gbc, 0, 4, 1, 1, 0, 10); add (gx, gbc, 0, 5, 1, 1, 0, 10); add (gxy, gbc, 0, 6, 1, 1, 0, 10); add (b, gbc, 1, 7, 1, 1, 100, 10); add (y, gbc, 0, 8, 1, 1, 0, 10); add (gy, gbc, 0, 9, 1, 1, 0, 10); add (gyx, gbc, 0, 10, 1, 1, 0, 10); add (sk, gbc, 1, 11, 1, 1, 100, 10); add (key, gbc, 0, 12, 1, 1, 0, 10); add (status, gbc, 1, 13, 1, 1, 100, 10); add (dhstart, gbc, 1, 14, 1, 1, 100, 10); add (bit_length_value, gbc, 1, 0, 1, 1, 100, 10); add (p_value, gbc, 1, 1, 1, 1, 100, 10); add (g_value, gbc, 1, 2, 1, 1, 100, 10); add (x_value, gbc, 1, 4, 1, 1, 100, 10); add (gx_value, gbc, 1, 5, 1, 1, 100, 10); add (gxy_value, gbc, 1, 6, 1, 1, 100, 10); add (y_value, gbc, 1, 8, 1, 1, 100, 10); add (gy_value, gbc, 1, 9, 1, 1, 100, 10); add (gyx_value, gbc, 1, 10, 1, 1, 100, 10); validate(); repaint(); rsaPanel=false; } Everthing seems okey however when i swith from one menu to another sometimes components are seen or apper in wrong places or mixed. where i'm doing wrong?

    Read the article

  • search data from FileReader in Java

    - by maya
    hi I'm new in java how to read and search data from file (txt) and then display the data in TextArea or Jtable. for example I have file txt contains data and I need to display this data in textarea after I clicked a button, I have used FileReader , and t1 t2 tp are attributes in the file import java.io.FileReader; import java.io.IOException; String t1,t2,tp; Ffile f1= new Ffile(); FileReader fin = new FileReader("test2.txt"); Scanner src = new Scanner(fin); while (src.hasNext()) { t1 = src.next(); textarea.setText(t1); t2 = src.next(); textarea.setText(t2); tp = src.next(); textarea.setText(tp); f1.insert(t1,t2,tp); } fin.close(); also I have used the inputstream DataInputStream dis = null; String dbRecord = null; try { File f = new File("text2.text"); FileInputStream fis = new FileInputStream(f); BufferedInputStream bis = new BufferedInputStream(fis); dis = new DataInputStream while ( (dbRecord = dis.readLine()) != null) { StringTokenizer st = new StringTokenizer(dbRecord, ":"); String t1 = st.nextToken(); String t2 = st.nextToken(); String tp = st.nextToken(); textarea.setText(textarea.getText()+t1); textarea.setText(textarea.getText()+t2); textarea.setText(textarea.getText()+tp); } } catch (IOException e) { // catch io errors from FileInputStream or readLine() System.out.println("Uh oh, got an IOException error: " + e.getMessage()); } finally { } but both of them don't work ,so please any one help me I want to know how to read data and also search it from file and i need to display the data in textarea . thanks in advance

    Read the article

  • Recursion causes exit to exit all JFrames (terminates app)

    - by Trizicus
    I have made an application that gives the user the option to open up a new spawn of the application entirely. When the user does so and closes the application the entire application terminates; not just the window. How should I go about recursively spawning an application and then when the user exits the JFrame spawn; killing just that JFrame and not the entire instance? Here is the relevant code: [...] JMenuItem newMenuItem = new JMenuItem ("New"); newMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new MainWindow(); } }); fileMenu.add(newMenuItem); [....] JMenuItem exit = new JMenuItem("Exit"); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }); fileMenu.add(exit); [...]

    Read the article

  • JSlider jump on mouse click

    - by Aly
    Hi, I have a JSlider which shows bet sizes (for a poker game) I am trying to achieve the effect that when a mouse click occurs the slider jumps forward by a bet amount (i.e. a big blind amount) rather than just incrementing by one. If the mouse click happens to the left of the bar i want it to decrement by a fixed amount else increment. I looked into attaching a mouse listener, but do not know how I can use the event to find out on what side of the bar the mouse was clicked. Any ideas?

    Read the article

  • Adding Columns to JTable dynamically

    - by martilyo
    I have an empty JTable, absolutely nothing in it. I need to dynamically generate its table columns in a certain way. A simplified version for the code I have for my attempt: @Action public void AddCol() { for (int i = 0; i < 10; i++) { TableColumn c = new TableColumn(i); c.setHeaderValue(getColNam(i)); table.getColumnModel().addColumn(c); } } But I'm getting an Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0 error. What am I doing wrong?

    Read the article

  • JTable custom header renderer that looks like other headers with nimbus look and feel?

    - by startoftext
    Any time I create a custom header renderer for a JTable it ends up not looking correct with the nimbus look and feel. The default table headers have a silvery gradient, custom renderers do not look that way. In the past I just avoided creating custom header renderers. Is it possible to copy the default look onto my new custom renderer? Basically I want to add a checkbox and have the area around it look like a normal column header, not just gray. I do know how to add the checkbox though and make it click-able. Thanks

    Read the article

  • JLabel which hides text after reaching certain length or number of values

    - by Patrick Kiernan
    The purpose of the JLabel is to show who a message is to, like in a mail client e.g. To: John, Mary, Peter, Frank, Tom, Harry I will have the names in a vector so can build up a string from that and then set the label's text to this string. However it has the potential to get quite long. I was think it might be nice to have something like this: To: John, Mary, Peter, Frank, Tom, Harry, ... Then when you click on the '...', it will expand more or just show a tool tip if you mouse over the ... Yes this idea is stolen from Thunderbird! I am open to other ideas, don't have to use a JLabel. Thanks.

    Read the article

  • are scala's mouse events working? how?

    - by coubeatczech
    Hi, I'm trying to create link-like label in scala. But no mouse events works for me. How are they supposed to work? class Hyperlink extends Label{ text = "hyperlink" reactions += { case MouseClicked(_,_,_,_,_) => println("mouse clicked")}} I put this in some panel and click over the label like a pro minesweeper player... and nothing shows up in console. Why?

    Read the article

  • How to draw a diary in swt

    - by Johannes
    Hey, I am searching for a good mode to develop a application which shows 7 days and 24 hours (weekly view), knows somebody if there is a good tutorial? Or which layout would you use to design this? It should be possible to add events with a beginning and ending time... Thanks in advance Johannes

    Read the article

  • Java: where should I put anonymous listener logic code?

    - by tulskiy
    Hi, we had a debate at work about what is the best practice for using listeners in java: whether listener logic should stay in the anonymous class, or it should be in a separate method, for example: button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // code here } }); or button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { buttonPressed(); } }); private void buttonPressed() { // code here } which is the recommended way in terms of readability and maintainability? I prefer to keep the code inside the listener and only if gets too large, make it an inner class. Here I assume that the code is not duplicated anywhere else. Thank you.

    Read the article

  • jtabbedpane different sized tabs

    - by Eric
    hi, im making a search function for a database that uses a jtabbedpane with one tab for a quick search, and one for an advanced search. the advanced search has quite a few more fields, so it needs to be larger, but i dont want the whole window to always be at the largest size for aesthetic reasons. i have added a change listener to the pane, and tried resizing the pane based on which tab it is, and the code executes when the tab is clicked, but does nothing. ive tried using tabbedSearchPane.setSize() followed by tabbedSearchPane.validate(), as well as resizing components around it using setSize+validate, and nothing seems to do anything. i really just need to know how to ACTUALLY change the size of a jtabbedpane.

    Read the article

  • Changing JButton background colour temporarily?

    - by sashep
    Hi, I'm super new to Java, and in need of some help. I'm making a little java desktop application where I basically have a grid of 4 JButtons ( 2 x 2 grid), and I need the background colour of individual JButtons to change, and after one second, change back to the original colour (the game I'm trying to make is like Simon, where you have to follow a pattern of buttons that light up). I have a vector that contains randomly generated numbers in the range of 1 to 4, and I want to be able to get each element from the vector and get the corresponding button to change to a different colour for one second (for example, if the vector contains 2 4 1, I would want button 2 to change, then button 4 to change, then button 1 to change). Is this possible or is there a better way to go about doing this with something other than JButtons? How do I implement this? Also, I'm running Mac OS X, which apparently (based on some things I've read on forums) doesn't like JButtons background changing (I think it's because of system look and feel), how can I change this so it works on mac? Thank you in advance for any help :)

    Read the article

  • GridBagConstraints problem-moved to left and size isn't the same

    - by Damir
    I have in Java two panels which need to have same layout, there is my functions for initializations panels. private void InitializePanelCom(){ pnlCom=new JPanel(); pnlCom.setSize(300,160); pnlCom.setLocation(10, 60); add(pnlCom); GridBagLayout gb=new GridBagLayout(); GridBagConstraints gc=new GridBagConstraints(); pnlCom.setLayout(gb); jLabelcommPort = setJLabel("Com Port : "); jLabelbaudRate = setJLabel("Baud Rate : "); jLabelplcAddress = setJLabel("Plc Address : "); jLabelsendTime = setJLabel("Send Time : "); jLabelx50 = setJLabel(" x 50 ms (2 - 99)"); jComboBoxcommPort = setJComboBox(commPortList); jComboBoxbaudRate = setJComboBox(bitRateList); jTextAreaPlcAddress = setJTextField(""); jTextAreaSendTime = setJTextField(""); gc.insets = new Insets(10,0,0,0); gc.ipadx = 120; gc.weightx = 1; gc.gridx = 0; gc.gridy = 0; gc.anchor=GridBagConstraints.EAST; pnlCom.add(jLabelcommPort,gc); gc.insets = new Insets(10,0,0,0); gc.ipadx = 120; gc.weightx = 1; gc.gridx = 1; gc.gridy = 0; gc.anchor=GridBagConstraints.EAST; pnlCom.add(jComboBoxcommPort,gc); gc.insets=new Insets(10,0,0,0); gc.ipadx=120; gc.weightx=1; gc.gridx=0; gc.gridy=1; gc.anchor=GridBagConstraints.EAST; pnlCom.add(jLabelbaudRate,gc); gc.insets=new Insets(10,0,0,0); gc.ipadx=120; gc.weightx=1; gc.gridx=1; gc.gridy=1; gc.anchor=GridBagConstraints.EAST; pnlCom.add(jComboBoxbaudRate,gc); gc.insets=new Insets(10,0,0,0); gc.ipadx=120; gc.weightx=1; gc.gridx=0; gc.gridy=2; gc.anchor=GridBagConstraints.EAST; pnlCom.add(jLabelplcAddress,gc); gc.insets=new Insets(10,0,0,0); gc.ipadx=120; gc.weightx=1; gc.gridx=1; gc.gridy=2; gc.anchor=GridBagConstraints.EAST; pnlCom.add(jTextAreaPlcAddress,gc); gc.insets=new Insets(10,0,0,0); gc.ipadx=120; gc.weightx=1; gc.gridx=0; gc.gridy=3; gc.anchor=GridBagConstraints.EAST; pnlCom.add(jLabelsendTime,gc); gc.insets=new Insets(10,0,0,0); gc.ipadx=120; gc.weightx=1; gc.gridx=1; gc.gridy=3; gc.anchor=GridBagConstraints.EAST; pnlCom.add(jTextAreaSendTime,gc); gc.insets=new Insets(10,0,0,0); gc.ipadx=120; gc.weightx=1; gc.gridx=2; gc.gridy=3; gc.anchor=GridBagConstraints.EAST; pnlCom.add(jLabelx50,gc); } ![alt text][1] private void InitializePanelTcp(){ pnlTcp=new JPanel(); pnlTcp.setSize(300,160); pnlTcp.setLocation(10, 60); add(pnlTcp); GridBagLayout gb=new GridBagLayout(); GridBagConstraints gc=new GridBagConstraints(); pnlTcp.setLayout(gb); lblIPAddress=setJLabel("IP Address : "); txtIPAddress=setJTextField(""); lblPort=setJLabel("Port : "); txtPort=setJTextField(""); cmbBaudRateTCP = setJComboBox(bitRateList); lblBaudRateTCP = setJLabel("Baud Rate : "); lblParityCheck=setJLabel("Parity check : "); txtParityCheck=setJTextField(""); gc.insets = new Insets(10,0,0,0); //gc.ipadx = 20; gc.weightx = 0.3; gc.gridx = 0; gc.gridy = 0; gc.anchor=GridBagConstraints.WEST; pnlTcp.add(lblIPAddress,gc); gc.insets = new Insets(10,0,0,0); //gc.ipadx = 80; gc.weightx = 0.7; gc.gridx = 1; gc.gridy = 0; gc.anchor=GridBagConstraints.WEST; pnlTcp.add(txtIPAddress,gc); gc.insets=new Insets(10,0,0,0); //gc.ipadx=120; gc.weightx=0.3; gc.gridx=0; gc.gridy=1; gc.anchor=GridBagConstraints.WEST; pnlTcp.add(lblPort,gc); gc.insets=new Insets(10,0,0,0); //gc.ipadx=80; gc.weightx=0.7; gc.gridx=1; gc.gridy=1; gc.anchor=GridBagConstraints.WEST; pnlTcp.add(txtPort,gc); gc.insets=new Insets(10,0,0,0); //gc.ipadx=120; gc.weightx=0.3; gc.gridx=0; gc.gridy=2; gc.anchor=GridBagConstraints.WEST; pnlTcp.add(lblBaudRateTCP,gc); gc.insets=new Insets(10,0,0,0); //gc.ipadx=0; gc.weightx=0.7; gc.gridx=1; gc.gridy=2; gc.anchor=GridBagConstraints.WEST; pnlTcp.add(cmbBaudRateTCP,gc); gc.insets=new Insets(10,0,0,0); //gc.ipadx=120; gc.weightx=0.3; gc.gridx=0; gc.gridy=3; gc.anchor=GridBagConstraints.WEST; pnlTcp.add(lblParityCheck,gc); gc.insets=new Insets(10,0,0,0); //gc.ipadx=0; gc.weightx=1.7; gc.gridx=1; gc.gridy=3; gc.anchor=GridBagConstraints.WEST; pnlTcp.add(txtParityCheck,gc); } Problem is that second panel (initializetcp, second picture doesn't look the same, labels are moved at left , it is different ). Can anybody help, I am new with GridBagContsraints at all ?

    Read the article

  • How to configure database for exe.file

    - by newbie123
    Recently I had created a Java Desktop Application, I wish to share it with my friends. I was thinking to convert it into exe file using exe4j, but as for the database part I not sure how to configure it so that the application can run on my friends desktop without re-configure the database again. I am using Microsoft Access, anyone can guide me how to do it?

    Read the article

< Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >