Search Results

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

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

  • How to resize controls at runtime in java

    - by user1349213
    Is there a way to resize a control, a JTextfield for example, at runtime in java? I want my textfield to have the resize cursors (just like when you point your cursor on the corner of a window) and will be able to resize on runtime. Ive read on the internet that vb6 and C# have those capabilities, is there anything for java? A sample code or a link to a good tutorial will be very much appreciated. Thank you.

    Read the article

  • Stealing the contents of another application's tree view

    - by User1
    I have an application with a very large TreeView control in Java. I want to get the contents of the tree control in a list (just strings not a JList) of XPath-like elements of leaves only. Here's an example root |-Item1 |-Item1.1 |-Item1.1.1 (leaf) |-Item1.2 (leaf) |-Item2 |-Item2.1 (leaf) Would output: /Item1/Item1.1/Item1.1.1 /Item1/Item1.2 /Item2/Item2.1 I don't have any source code or anything handy like that. Is there I tool I can use to dig into the Window item itself and pull out this data? I don't mind if there are a few post-processing steps because typing it in by hand is my only other option.

    Read the article

  • How to display a tree of objects in a JTree?

    - by paul
    Imagine a collection of objects such as World, Country, Region and City. World contains a list of Country objects, Country contains a list of Region objects etc. I would like to represent this structure in a JTree and be able to add, remove and move objects around the tree. Can I easily create a TableModel from this structure? World would be the root object and I would need to perform some object-specific rendering. Any one know of an appropriate tutorial?

    Read the article

  • How to use Map element as text of a JComboBox

    - by llm
    I am populating a JComboBox (using addItem()) with all the elements of a collection. Each element in the collection is a HashMap (so its a ComboBox of Hashmaps..). My question is - Given that I need each item to be a HashMap how do I set the text to apear in the combobox on the GUI? It needs to be the value of a certain key in the map. Normally if I am populating a combobox with my own type, I would just overide the toString() method...but I am not sure how to acheive this since I am using a Java HashMap. Any ideas (if possible, without implementing my own HashMap)? Update: It seems like there isn't anyway to avoid having the object int the JComboBox overide toString() if I want custom functionality..I wish there was a way to (1) specify the objects to be loaded into the JComboBox and (2) specify how these objects are to appear in the GUI.

    Read the article

  • Setting the height of a row in a JTable in java

    - by Douglas Grealis
    I have been searching for a solution to be able to increase the height of a row in a JTable. I have been using the setRowHeight(int int) method which compiles and runs OK, but no row[s] have been increased. When I use the getRowHeight(int) method of the row I set the height to, it does print out the size I increased the row to, so I'm not sure what is wrong. The code below is a rough illustration how I am trying to solve it. My class extends JFrame. String[] columnNames = {"Column 1", "Column 2", "Column 1 3"}; JTable table = new JTable(new DefaultTableModel(columnNames, people.size())); DefaultTableModel model = (DefaultTableModel) table.getModel(); int count =1; for(Person p: people) { model.insertRow(count,(new Object[]{count, p.getName(), p.getAge()+"", p.getNationality})); count++; } table.setRowHeight(1, 15);//Try set height to 15 (I've tried higher) Can anyone tell me where I am going wrong? I am trying to increase the height of row 1 to 15 pixels?

    Read the article

  • DefaultTableCellRenderer getTableCellRendererComponent never gets called

    - by Dean Schulze
    I need to render a java.util.Date in a JTable. I've implemented a custom renderer that extends DefaultTableCellRenderer (below). I've set it as the renderer for the column, but the method getTableCellRendererComponent() never gets called. This is a pretty common problem, but none of the solutions I've seen work. public class DateCellRenderer extends DefaultTableCellRenderer { String sdfStr = "yyyy-MM-dd HH:mm:ss.SSS"; SimpleDateFormat sdf = new SimpleDateFormat(sdfStr); public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value instanceof Date) { this.setText(sdf.format((Date) value)); } else logger.info("class: " + value.getClass().getCanonicalName()); return this; } } I've installed the custom renderer (and verified that it has been installed) like this: DateCellRenderer dcr = new DateCellRenderer(); table.getColumnModel().getColumn(2).setCellRenderer(dcr); I've also tried table.setDefaultRenderer( java.util.Date.class, dcr ); Any idea why the renderer gets installed, but never called?

    Read the article

  • Why is it not saying I won?

    - by Itachi
    This is my if statement... The buttons show up like this: This is my if statement if((buttons[3].getName()=="x" && buttons[6].getName()=="x" && buttons[9].getText()=="x")||(buttons[2].getName()=="x" && buttons[5].getName()=="x" && buttons[8].getName()=="x")|| ((buttons[1].getName()=="x") && (buttons[4].getName()=="x") && (buttons[7].getName()=="x"))){ JOptionPane.showMessageDialog(null,"X Wins"); } So if I select the 1st, 4th and 7th buttons (the left most 3 buttons) why does it not say "X Wins"? As a sidenote, yes the buttons should have the name "x"

    Read the article

  • How to make sketching kind module in java?

    - by Nitz
    Hey Guys I am trying to make one software on which user can make any sketch and make any drawing kind of thing. i am trying to get reference from this two great software. 1. Notelab 2. Jarnal But both having great and many facility in it. But In my software i want only sketching-drawing, so how to do that? I tried to use Canvas but i don't get how to use it?

    Read the article

  • How to select item in jComboBox

    - by jtnire
    Hi folks, I have a jComboBox that I am populating with some objects. The objects are of a type which I have made myself, and include a String and an int. The object's toString method returns the String, which is displayed in the Combo Box. Now, I wish to select an item in the Combo Box with code. How do I do this? There are multiple items starting with the same letter Thanks

    Read the article

  • How can I change my JLabel to look like a table cell with Substance?

    - by DR
    I have a custom TableCellRenderer which returns a JLabel as the renderer component. Naturally the table cell now looks like a label and no longer like a table cell, which makes a difference especially when using Substance. Is it possible to modify the label so that the LaF renders it like an ordinary table cell? The best I could do was setting the background color of the label, but the borders and transition effets are missing.

    Read the article

  • "Change" panel on jframe

    - by bog
    I have 2 panels, the first one is the menu, and the second is the application main panel. Firstly the menu panel shows up, than i need to switch to the other panel if a specific button is pressed on the menu (the menu is hidden but the app returns to it after running is completed). && i need to resize the frame too if it's possible. can i do this somehow?

    Read the article

  • How to set JComboBox not to select an element when created? (Java)

    - by Alex Cheng
    Hi all. Problem: I am using JComboBox, and tried using setSelectionIndex(-1) in my code (this code is placed in caretInvoke()) suggestionComboBox.removeAllItems(); for (int i = 0; i < suggestions.length; i++) { suggestionComboBox.addItem(suggestions[i]); } suggestionComboBox.setSelectedIndex(-1); suggestionComboBox.setEnabled(true); This is the initial setting when it was added to a pane: suggestionComboBox = new JComboBox(); suggestionComboBox.setEditable(false); suggestionComboBox.setPreferredSize(new Dimension(25, 25)); suggestionComboBox.addActionListener(new SuggestionComboBoxListener()); When the caretInvoke triggers the ComboBox initialisation, even before the user selects an element, the actionPerformed is already triggered (I tried a JOptionPane here): First popup (notice that "flow byte_jump" is selected): Second popup (I think the setSelectionIndex is executed) Then in the end: The problem is: My program autoinserts the selected text when the user selects an element from the ComboBox. So without the user selecting anything, it is automatically inserted already. How can I overcome the problem in this situation? Thanks.

    Read the article

  • JTable cells not rendering shapes properly

    - by Andrew
    I'm trying to render my JTable cells with a subclassed JPanel and the cells should appear as coloured rectangles with a circle drawn on them. When the table displays initially everything looks OK but then when a dialog or something is displayed over the cells when it is removed the cells that have been covered do not rendered properly and the circles are broken up etc. I then have to move the scroll bar or extend the window to get them to redraw properly. The paintComponent method of the component I'm using to render the cells is below: protected void paintComponent(Graphics g) { setOpaque(true); super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; GradientPaint gradientPaint = new GradientPaint(new Point2D.Double(0, 0), Color.WHITE, new Point2D.Double(0, getHeight()), paintRatingColour); g2d.setPaint(gradientPaint); g2d.fillRect(0, 0, getWidth(), getHeight()); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); Rectangle clipBounds = g2d.getClipBounds(); int x = new Double(clipBounds.getWidth()).intValue() - 15; int y = (new Double(clipBounds.getHeight()).intValue() / 2) - 6; if (level != null) { g2d.setColor(iconColour); g2d.drawOval(x, y, width, height); g2d.fillOval(x, y, width, height); } }

    Read the article

  • Resultset (getter/setter class) object not deleting old values at 2nd Time execution in swin

    - by user2384525
    I have summarizeData() method and called so many time for value retrieve. but first time is working file but 2nd time execution value is increasing in HashMap. void summarizeData() { HashMap outerMap = new HashMap(); ArrayList list = new ArrayList(dataClass.getData()); for (int indx = 0; indx < list.size(); indx++) { System.out.println("indx : " + indx); Resultset rs = new Resultset(); rs = (Resultset) list.get(indx); if (rs != null) { int id = rs.getTestCaseNumber(); if (id > 0) { Object isExists = outerMap.get(id); if (isExists != null) { //System.out.println("found entry so updating"); Resultset inRs = new Resultset(); inRs = (Resultset) isExists; if (inRs != null) { int totExec = inRs.getTestExecution(); int totPass = inRs.getTestCasePass(); int totFail = inRs.getTestCaseFail(); // System.out.println("totE :" + totExec + " totP:" + totPass + " totF:" + totFail); int newRsStat = rs.getTestCasePass(); if (newRsStat == 1) { totPass++; inRs.setTestCasePass(totPass); } else { totFail++; inRs.setTestCaseFail(totFail); } totExec++; // System.out.println("id : "+id+" totPass: "+totPass+" totFail:"+totFail); // System.out.println("key : " + id + " val : " + inRs.getTestCaseNumber() + " " + inRs.getTestCasePass() + " " + inRs.getTestCaseFail()); inRs.setTestExecution(totExec); outerMap.put(id, inRs); } } else { // System.out.println("not exist so new entry" + " totE:" + rs.getTestExecution() + " totP:" + rs.getTestCasePass() + " totF:" + rs.getTestCaseFail()); outerMap.put(id, rs); } } } else { System.out.println("rs null"); } } Output at 1st Execution: indx : 0 indx : 1 indx : 2 indx : 3 indx : 4 indx : 5 indx : 6 indx : 7 indx : 8 indx : 9 indx : 10 totE :1 totP:1 totF:0 indx : 11 totE :1 totP:1 totF:0 indx : 12 totE :1 totP:1 totF:0 indx : 13 totE :1 totP:1 totF:0 indx : 14 totE :1 totP:1 totF:0 indx : 15 totE :1 totP:1 totF:0 indx : 16 totE :1 totP:1 totF:0 indx : 17 totE :1 totP:1 totF:0 indx : 18 totE :1 totP:1 totF:0 indx : 19 totE :1 totP:1 totF:0 Output at 2nd Execution: indx : 0 indx : 1 indx : 2 indx : 3 indx : 4 indx : 5 indx : 6 indx : 7 indx : 8 indx : 9 indx : 10 totE :2 totP:2 totF:0 indx : 11 totE :2 totP:2 totF:0 indx : 12 totE :2 totP:2 totF:0 indx : 13 totE :2 totP:2 totF:0 indx : 14 totE :2 totP:2 totF:0 indx : 15 totE :2 totP:2 totF:0 indx : 16 totE :2 totP:2 totF:0 indx : 17 totE :2 totP:2 totF:0 indx : 18 totE :2 totP:2 totF:0 indx : 19 totE :2 totP:2 totF:0 while i required same output on every execution.

    Read the article

  • JButton and next/previous object of treemap

    - by supacat
    I have this problem: 1) There are objects placed in the TreeMap through the JTextField. (Phonebook-like program). 2)There are buttons that implement view of available records in TreeMap. When you click on these buttons next / previous available objects of TreeMap displaying in JTextField. (scroll through the available records). I tried this code, but I didn't work :/ btn[4].addActionListener(new ActionListener(){ Iterator iter = tree.keySet().iterator(); public void actionPerformed(ActionEvent e) { if (iter.hasNext()){ String str = iter.next().toString(); fldFio.setText(str); fldNumber.setText(tree.get(str)); } } });

    Read the article

  • How to listen to JComboBox's width changes?

    - by agnieszka
    I tried PropertyChangeListener with property set to "width", "Width", "size" and "Size". PropertyChangeListener widthChangeListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { //code } }; streamsComboBox.addPropertyChangeListener("width", widthChangeListener); projectsComboBox.addPropertyChangeListener("width", widthChangeListener); vobsComboBox.addPropertyChangeListener("width", widthChangeListener); Nothing works - the handler method is never fired. What should I do to handle JComboBox's size change? Where does the property name come from anyway?

    Read the article

  • How to get JTree expanded?

    - by Dzmitry Zhaleznichenka
    I have a wizard with several screens where user has to fill his/her details for further processing. At the second screen I have a radio group with three radio buttons that enable additional elements. To proceed, user has to choose one of them. When user selects third button, single-selection JTree filled in with data enables and user has to select an option from it. Then user has to press "Next" to get to next screen. The option he\she had selected is stored as a TreePath. So far so good. My problem is the following. If the user wants to come back from the following screen to the screen with a JTree, I want to provide him\her with the JTree expanded to the option that had been selected and to highlight the option. However, whatsoever I try to do for that (any combinations of expandPath, scrollPathToVisible, addSelectionPath, makeVisible) always provides me with a collapsed tree. I try to expand both leaves and nodes. My code looks like this: rbProcessJTree.setSelected(isProcessJTree()); if (null != getSelectedTablePath()){ trTables.addSelectionPath(getSelectedTablePath()); trTables.expandPath(getSelectedTablePath()); trTables.scrollPathToVisible(getSelectedTablePath()); } When setSelected() is called, state change listener is invoked that enables JTree. The model is loaded during the form initialization. Each time I switch between screens, I save the input data from previous screen and dispose it. Then, when I need to open previous screen back, I save data from the following screen, dispose it, load data to this screen and show it. So each time the screen is generating from scratch. Could you please explain, what sequence of operations has to be done to get JTree expanded in a newly created form,with data model loaded and selection path provided?

    Read the article

  • JLabel transparency problem

    - by Rendicahya
    I have a dark-gray JPanel with a JLabel on it. I set new Color(0, 0, 0, .5f) (tranparent) as the background of the JLabel and I change the text several times using a button. The problem is, everytime the text is changed, the previous text still remains behind the new text. I change the text from "123456789" to "1234567", "12345" and "123". Here is the screenshot: How do I get rid of this "shadow"? Here's the code: public class TransparentJLabel extends JFrame { private int i = 0; private String[] value = {"123456789", "1234567", "12345", "123", "1"}; public TransparentJLabel() { setSize(300, 160); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setLayout(null); JPanel panel = new JPanel(); panel.setBackground(new Color(102, 102, 102)); panel.setLayout(null); panel.setBounds(0, 0, 300, 160); final JLabel label = new JLabel(); label.setText(value[0]); label.setFont(new Font("Times New Roman", 1, 36)); label.setForeground(new Color(255, 255, 255)); label.setBackground(new Color(0, 0, 0, .5f)); label.setHorizontalAlignment(SwingConstants.CENTER); label.setOpaque(true); label.setBounds(10, 10, 270, 70); JButton button = new JButton(); button.setText("Change"); button.setBounds(100, 90, 90, 25); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { label.setText(value[++i]); } }); panel.add(label); panel.add(button); add(panel); } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { new TransparentJLabel().setVisible(true); } }); } }

    Read the article

  • ImageIcon loads no image

    - by neville
    I'm trying to get image built from tiled set of images So to JPanel I'm adding JButtons with ImageIcons. All images are in folder with my classes (NetBeans), and they're named u1, u2, ..., u16. But on button there is no image shown. What am I doing wrong ? JPanel panel = new JPanel(new GridLayout(4, 4, 3, 3)); for (int i = 1; i < 17; i++) { JLabel l = new JLabel(new ImageIcon("u"+i+".jpg"), JLabel.CENTER); l.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); panel.add(l); }

    Read the article

  • Java: JButton actionListener explantation

    - by MrDoctorProfessorTyler
    I am extremely confused as to how a JButton works. I have read over the oracle documents of the JButton, but I have failed to see how a JButton can have an actionlistener added to it. I have really always wondered how things like JFrames and all that can have things like .addMouseListener and all that. Can anyone explain how a JButton can have an actionListener added to it like the .addActionListener(...) syntax?

    Read the article

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