can scrollPane be resized automatically?


when we resize a JFrame, is it possible to resize the containing scroll pane with the frame automatically is there any function
Posted On: Monday 22nd of October 2012 02:49:59 AM Total Views:  100
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




cannot resolve symbol

I am getting this erro when I compile my code. I have worked out all the other bugs and now understand where they came from, but this one is a little baffeling to me. I have not changed any of the code in the area of the line that is giving me the problem (JComboBox interest = new JComboBox(interestArray) . Any ideas cannot resolve symbol symbol: constructor JComboBox (java.lang.String) import javax.swing.*; //importing the ability to create and use a frame import java.awt.*; //importing the swing functions like the combo box import java.awt.event.*; import java.lang.String; import java.io.*; import java.math.*; public class MortgageFrame5 extends JFrame implements ItemListener, ActionListener, Runnable{ //setting up my variables String paythis; double monthly; int a; int t; double I; double total; int loop; double balance; String actInt; int totalGraph; int interestGraph; int principalGraph; int pie[]; int pieDegree[]; //creating lables, boxes, arrays, and buttons JLabel amountLabel = new JLabel ("House cost in dollars:"); JComboBox amount = new JComboBox();{ amount.addItem("$100,000"); amount.addItem("$125,000"); amount.addItem("$150,000"); amount.addItem("$175,000"); amount.addItem("$200,000"); amount.addItem("$225,000"); amount.addItem("$250,000"); amount.addItem("$275,000"); } JLabel tILabel = new JLabel ("Payment term and rate:"); String[] termsInterestArray = {"7 years at 5.35%", "15 years at 5.5%", "30 years at 5.75%"}; String[] termsArray = {"7 years", "15 years", "30 years"}; String interestArray = readData(); private String readData(){ String s = null; try{ File interestRate = new File("interestRate.txt"); FileInputStream fileStream = new FileInputStream(interestRate); BufferedReader stream = new BufferedReader(new InputStreamReader(fileStream)); s = new String(stream.readLine()); } catch (Exception e){ System.err.println("Could not read file."); } return s; } JComboBox tI = new JComboBox(termsInterestArray); JComboBox term = new JComboBox(termsArray); JComboBox interest = new JComboBox(interestArray); JButton calculate = new JButton("Calculate"); JButton quit = new JButton("Quit"); JLabel heading = new JLabel ("Payment | Loan Balance | Interest Paid"); JTextArea future = new JTextArea (180, 40); JScrollPane futureInfo = new JScrollPane(future); JCheckBox seperateCheck = new JCheckBox("Check to select term and interest seperately"); JCheckBox tICheck = new JCheckBox("Check to select term and interest together"); ButtonGroup select = new ButtonGroup(); public MortgageFrame5(){ //setting up the frame and frame characteristics setTitle("Mortgage calculator"); setSize(340,350); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); //user can see the box FlowLayout flo = new FlowLayout(); Container pane = getContentPane(); future.setLineWrap(true); select.add(seperateCheck); select.add(tICheck); //setting the default layout manager and adding everything to the container pane.setLayout(flo); pane.add(amountLabel); pane.add(amount); pane.add(tILabel); pane.add(tICheck); pane.add(tI); pane.add(seperateCheck); pane.add(term); pane.add(interest); pane.add(calculate); pane.add(quit); pane.add(heading); pane.add(futureInfo); setContentPane(pane); //setting up the listeners amount.addItemListener(this); tI.addItemListener(this); term.addItemListener(this); interest.addItemListener(this); seperateCheck.addItemListener(this); tICheck.addItemListener(this); calculate.addActionListener(this); quit.addActionListener(this); repaint(); // retrieving the interest rates from the file } //this is where the program will act upon the user selections public void itemStateChanged(java.awt.event.ItemEvent e){ } //This is where the calculate button functionality comes from public void actionPerformed(ActionEvent event){ if(event.getSource() == calculate){ String strA = (String)amount.getSelectedItem(); if (strA.equals("$100,000")){ a = 100000; } else if (strA.equals("$125,000")){ a = 125000; } else if (strA.equals("$150,000")){ a = 150000; } else if (strA.equals("$175,000")){ a = 175000; } else if (strA.equals("$200,000")){ a = 200000; } else if (strA.equals("$225,000")){ a = 225000; } else if (strA.equals("$250,000")){ a = 250000; } else if (strA.equals("$275,000")){ a = 275000; } if (seperateCheck.isSelected()){ String strT = (String)term.getSelectedItem(); if (strT.equals("7 years")){ t = 7*12; } else if (strT.equals("15 years")){ t = 15*12; } else if (strT.equals("30 years")){ t = 30*12; } String strI = (String)interest.getSelectedItem(); if (strI.equals("5.35%")){ I = 0.0535; } else if (strI.equals("5.5%")){ I = 0.055; } else if (strI.equals("5.75%")){ I = 0.0575; } } else if (tICheck.isSelected()){ String strT = (String)tI.getSelectedItem(); if (strT.equals("7 years at 5.35%")){ t = 7*12; I = 5.35; } else if (strT.equals("15 years at 5.5%")){ t = 15*12; I = 5.5; } else if (strT.equals("30 years at 5.75%")){ t = 30*12; I = 5.75; } } } total = ((I/1200) + (I/1200)/(Math.pow(1+(I/1200),t) -1)) * 100 * a; monthly = total/t; balance = total; actInt = ("$" + (Math.round((monthly * I)* 100) / 100.00)); //setting up the loop to run and print the information into the text area future.setText("\n"); for (int loop = 1; loop
VIEWS ON THIS POST

75

Posted on:

Thursday 18th October 2012
View Replies!

Text canvas vertical scroll

, I have an application that draws strings of text on a canvas doing word wrapping and breaking whenever necessary. Canvas' height is initially zero and grows as strings are drawn onto it. The final canvas' height is calculated as a last step of the paint() method. Vertical text scrolling has to be implemented as well, for which purpose I'm using ScrollPane. I'm experiencing one problem here: it looks like I cannot dynamically set the canvas' height by the time all strings have been drawn on it. The getPreferredSize() method is called by the layout manager when the canvas class is instantiated and overriding the method doesn't help much. The only way to make scrolling work is to resize the application frame as soon as it's created at least one pixel in any direction. Then apparently the getPreferredSize() method is called again and the updated canvas' size is set. Using setSize() explicitly doesn't help for some reason... Resizing the frame seems to fire some hidden underlying mechanism which sets the updated size of the canvas and let the scrolling work perfectly... Another way to make it work is to set preferred size to a constant value, eg. public Dimension getPreferredSize() { return new Dimension(200, 828); }
VIEWS ON THIS POST

54

Posted on:

Thursday 18th October 2012
View Replies!

can I i18nze this ?

ranchers. How can I i18nize the text displayed on the buttons of JFileChooser or the standard dialogs
VIEWS ON THIS POST

60

Posted on:

Thursday 18th October 2012
View Replies!

How can I display an image on an AWT panel

I can't use swing, so don't tell me the way of relate to swing
VIEWS ON THIS POST

60

Posted on:

Thursday 18th October 2012
View Replies!

how can I get the merge table cell and get the location

how can I get the merge table cell and get the location --------------------------------------- 1 |2 |3 |4 | --------------------------------------- 5 |6 |7 |8 | ---------------------------------------
VIEWS ON THIS POST

51

Posted on:

Sunday 21st October 2012
View Replies!

JTable adding a RowFilter can no longer add to the table get invalid range?

After adding a TableRowSorter to a table and its corresponding model any corresponding adds specifically at firetabletablerowsinserted cause exceptions. It is clear from testing that the GetRowCount() is returning a value past the models range. However it does not make sense to me how to continue to add values to the table after a sorter or filter has been added As an example, I set the row filter before adding anything to the table then add a value to the table with the following calls in my model: this.addRow(row, createRow(trans,row)); this.fireTableRowsInserted(this.getRowCount(), this.getRowCount());
VIEWS ON THIS POST

72

Posted on:

Monday 22nd October 2012
View Replies!

How can I make a GUI like this?

.I am new here.How can I make a gui like this. I have make a Demo like this..But when I click on the keyboard image,the Gui didn't exit . Now, I know CellRenderer only can display the UI.My English is poor,
VIEWS ON THIS POST

46

Posted on:

Monday 22nd October 2012
View Replies!

can't understand draw()

the draw(shape s) method is declared abstarct in the Graphics2D class then can someone explain that how is it able to perform any functionality at all because according to me if a method is abstract it doesn't have any definition .
VIEWS ON THIS POST

60

Posted on:

Monday 22nd October 2012
View Replies!

cannot find symbol...class ParseException

MaskFormatter formatter = null; try { formatter = new MaskFormatter("#########"); } catch (ParseException e) { e.printStackTrace(); }
VIEWS ON THIS POST

75

Posted on:

Monday 22nd October 2012
View Replies!

how can i set jdialog title to support Unicode languages

i have a jdialog,i need to set it's title to different language. languages which are supported by unicode. how can i do this.
VIEWS ON THIS POST

51

Posted on:

Monday 22nd October 2012
View Replies!

BackgroundPanel.java cannot be placed in BorderLayout.NORTH

i am trying to put a picture on the top of my swing GUI that stretches horizontally to fit the width of the window as it resizes http://www.camick.com/java/source/BackgroundPanel.java this is the code for a commonly used function that scales images to their components size. it works by overloading the paintcontainer class, which is called every time the window resizes, which then calls the paint class. they simply grab the size of the container and draw the image to those dimensions the image that needs to be resized must be placed in BorderLayout.NORTH, because the rest of my GUI is in BorderLayout.CENTER, but BackgroundPanel cant be placed in NORTH, the image disappears, even with a minimum size set. it cant be placed inside a panel inside a panel inside NORTH either. ive been reading over the code for BackgroundPanel and its driving me crazy i cant figure out why here is some short example code, not my program but it simplifies the problem: import java.awt.*; import javax.swing.*; import java.awt.event.WindowEvent; public class JPanel1 extends JFrame { public static void main(String[] args) { new JPanel1(); } public JPanel1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); add(mainJPanel()); pack(); setVisible(true); } //debug space center to streatch private JPanel mainJPanel() { JPanel JPanel = new JPanel(); BorderLayout layout = new BorderLayout(); this.setMinimumSize( new Dimension( 224, 224 ) ); JPanel.setLayout(layout); JPanel.add(mainJPanel2(),BorderLayout.NORTH); return(JPanel); } //debug space center to streatch private JPanel mainJPanel2() { JPanel JPanel = new JPanel(); BorderLayout layout = new BorderLayout(); JPanel.setLayout(layout); JPanel.add(JPanel2(),BorderLayout.CENTER); return(JPanel); } private JPanel JPanel2() { BorderLayout layout = new BorderLayout(); this.setLayout(layout); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image duke = toolkit.getImage("sun.jpg"); BackgroundPanel panel = new BackgroundPanel(duke, BackgroundPanel.SCALED); //panel.setMinimumSize( new Dimension( 224, 224 ) ); this.setMinimumSize( new Dimension( 224, 224 ) ); GradientPaint paint = new GradientPaint(0, 0, Color.BLUE, 600, 0, Color.RED); panel.setPaint(paint); return panel; } //exit when closed public void processWindowEvent(WindowEvent event) { if(event.getID() == WindowEvent.WINDOW_CLOSING) System.exit(0); } }
VIEWS ON THIS POST

80

Posted on:

Monday 22nd October 2012
View Replies!

if jtab properties disabled,can we get the changes

i am new to Swing framework.my problem is, in jtab if we disable the properties, then can we get the changes which are made to the jtab's help me cheers........
VIEWS ON THIS POST

56

Posted on:

Monday 22nd October 2012
View Replies!

How can i Convert Java JTree Object to XML Format ?? :: Need your valuable suggestions

I am King here. I am new to Java Swing programming. I got new task in my company. Here, i need to generate a dynamic XML file from Editable JTree. I have successfully coded for editable JTree. In this tree we can add and delete new nodes. Means, the number of elements will vary from user to user. User will create their own customized tree according to their requirements. I tried XStream also. It is working for normal class Objects only. Not for JTree object. It is generating XML also. But, not according to Tree structure, according to the JTree classes hierarchy. If they click on GenerateXML, we need to generate an XML file according to the tree structure. I am new to swing programming. So, can any one help me for this please............ my Existing code is as follows: /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author King Kranthi */ package xmlapp.examples; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Enumeration; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.MutableTreeNode; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; public class EditableTree extends JFrame { private DefaultMutableTreeNode m_rootNode = new DefaultMutableTreeNode("new"); private DefaultTreeModel m_model = new DefaultTreeModel(m_rootNode); private JTree m_tree = new JTree(m_model); private JButton m_addButton = new JButton("Add Node"); private JButton m_delButton = new JButton("Delete Node"); private JButton m_xmlButton = new JButton("Generate XML"); private JButton m_searchButton = new JButton("Search Node"); private JButton m_searchAndDeleteButton = new JButton("Search and Delete Node"); private JTextField m_searchText; public EditableTree() { m_tree.setEditable(true); m_tree.setSelectionRow(0); JScrollPane scrollPane = new JScrollPane(m_tree); getContentPane().add(scrollPane, BorderLayout.CENTER); JPanel panel = new JPanel(); m_addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selNode = (DefaultMutableTreeNode) m_tree .getLastSelectedPathComponent(); if (selNode == null) { return; } DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("new"); m_model.insertNodeInto(newNode, selNode, selNode.getChildCount()); TreeNode[] nodes = m_model.getPathToRoot(newNode); TreePath path = new TreePath(nodes); m_tree.scrollPathToVisible(path); m_tree.setSelectionPath(path); m_tree.startEditingAtPath(path); } }); panel.add(m_addButton); m_delButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selNode = (DefaultMutableTreeNode) m_tree .getLastSelectedPathComponent(); removeNode(selNode); } }); panel.add(m_delButton); m_xmlButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selNode = (DefaultMutableTreeNode) m_tree .getLastSelectedPathComponent(); generateXML(); } }); panel.add(m_xmlButton); JPanel searchPanel = new JPanel(); searchPanel.setBorder(BorderFactory.createEtchedBo rder()); m_searchText = new JTextField(10); searchPanel.add(m_searchText); m_searchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode node = searchNode(m_searchText.getText()); if (node != null) { TreeNode[] nodes = m_model.getPathToRoot(node); TreePath path = new TreePath(nodes); m_tree.scrollPathToVisible(path); m_tree.setSelectionPath(path); System.out.println(nodes.length); } else { System.out.println("Node with string '" + m_searchText.getText() + "' not found"); } } }); searchPanel.add(m_searchButton); m_searchAndDeleteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode node = searchNode(m_searchText.getText()); if (node != null) { removeNode(node); } else { System.out.println("Node with string '" + m_searchText.getText() + "' not found"); } } }); searchPanel.add(m_searchAndDeleteButton); panel.add(searchPanel); getContentPane().add(panel, BorderLayout.SOUTH); setSize(1000, 700); setVisible(true); } public DefaultMutableTreeNode searchNode(String nodeStr) { DefaultMutableTreeNode node = null; Enumeration e = m_rootNode.breadthFirstEnumeration(); while (e.hasMoreElements()) { node = (DefaultMutableTreeNode) e.nextElement(); if (nodeStr.equals(node.getUserObject().toString())) { System.out.println("==>"+node); return node; } } return null; } public void removeNode(DefaultMutableTreeNode selNode) { if (selNode == null) { return; } MutableTreeNode parent = (MutableTreeNode) (selNode.getParent()); if (parent == null) { return; } MutableTreeNode toBeSelNode = getSibling(selNode); if (toBeSelNode == null) { toBeSelNode = parent; } TreeNode[] nodes = m_model.getPathToRoot(toBeSelNode); TreePath path = new TreePath(nodes); m_tree.scrollPathToVisible(path); m_tree.setSelectionPath(path); m_model.removeNodeFromParent(selNode); } private MutableTreeNode getSibling(DefaultMutableTreeNode selNode) { MutableTreeNode sibling = (MutableTreeNode) selNode.getPreviousSibling(); if (sibling == null) { sibling = (MutableTreeNode) selNode.getNextSibling(); } return sibling; } public void generateXML(){ DefaultMutableTreeNode node = null; //Enumeration e = m_rootNode.breadthFirstEnumeration(); //BFS int e = m_rootNode.getChildCount(); System.out.println(e); } public static void main(String[] arg) { EditableTree editableTree = new EditableTree(); } }
VIEWS ON THIS POST

61

Posted on:

Monday 22nd October 2012
View Replies!

Global keyboard reading (for barcode scanner)

I am going to use a barcode scanner device that simulates keyboard input (i.e. the system thinks it's a keyboard). my barcodes begin with a specific prefix (say, "@#@") and end with a specific suffix, which is how I differentiate them from the actual keyboard input. I need to listen to barcodes globally across the application, which can be accomplished using Toolkit.getDefaultToolkit().addAWTEventListener. I also need to intercept and suppress barcodes for the rest of my application - e.g. if the focus was on JTextField, it should NOT show the barcode entry. This, I am not sure how to accomplish. Any suggestions
VIEWS ON THIS POST

50

Posted on:

Monday 22nd October 2012
View Replies!

Why can't i control location of label?

I have background picture and a label that is suppose to go on top of it but i can't seem to control it's location. Setting the location seems to have no effect. I tried increasing the numbers but the textLabel won't budge. It's not exactly at (0,0) of the panel. It is actual 1/4 to the right and less than 1 row down. public BGPanel(ImageIcon background, String msg) { myIcon = background; JLabel textLabel = new JLabel(msg); textLabel.setFont(new Font("sanSerif", Font.BOLD, 12)); textLabel.setForeground(Color.pink); textLabel.setLocation(0,0); //
VIEWS ON THIS POST

33

Posted on:

Monday 22nd October 2012
View Replies!

can't set cursor placement when clicking in a JFormattedTextField...

Ranchers, I have a small but persistent problem. I have a JFormattedTextField created with a MaskFormatter, so that it will only accept eight characters for input. MaskFormatter eightCharMax = null; // limit input size try { eightCharMax = new MaskFormatter("********"); } catch (ParseException e) { // Swallow exception: exception impossible in this scenario } ... customerIDField = new JFormattedTextField(eightCharMax);
VIEWS ON THIS POST

65

Posted on:

Monday 22nd October 2012
View Replies!

ActionListener: Non-static variable 'this' cannot be referenced from a non-static context????

Hi ! I'm not sure why the below code is giving me the error message: 'non-static variable this cannot be referenced from a non-static context', which points to tl, my TimerListener, which implements ActionListener. Is 'this' implied somewhere there that I'm not seeing I'm not sure what 'this' would have to do with my TimerListener\t I've Googled extensively and can't really find any explanation in my text. Does anyone have any ideas or an explanation If need be, I can post my other classes, but I don't think that's the issue here.
VIEWS ON THIS POST

111

Posted on:

Monday 22nd October 2012
View Replies!

how can i drow lines on image with swing

all i have simple Jframe that loads image and display it on Jpanel works great . now i want to draw lines .. simple lines on that image what should i look into , can you please give me link to something that does such thing
VIEWS ON THIS POST

43

Posted on:

Monday 22nd October 2012
View Replies!

Looking for examples of what can be done with Java's GUI tools

all Getting back into the java programming world for the first time in years and am wondering just want are the limits of java's GUI tools I'm hoping that the metal look that greeted me when I last played with Swing is now able to be made at least sort of attractive now. Can someone point me to some examples of Java programs that are pushing the envelope GUI wise in Java Hopefully I explained what I'm after well enough, and
VIEWS ON THIS POST

56

Posted on:

Monday 22nd October 2012
View Replies!

How can I catch the CTRL_C or CTRL_V event

Dear . How can I catch the Ctrl_C or Ctrl_V event in the StyledText widget. Which event listener should I use. KeyListener or anyone else.
VIEWS ON THIS POST

63

Posted on:

Monday 22nd October 2012
View Replies!