SEARCH YOUR SOLUTION HERE  

display all data from database into jtable

i want to display all data from database into Jtable
but my some cell consist of more characters of data because of which we have to scroll jtable a lot
so
i thought of displaying all data in jtextarea(by displaying it in nextline by using("\n")where ever necessary ) & then insert jtextarea in each cell of jtable

but i dont know code please post a code which would help me

Posted On: Wednesday 17th of October 2012 06:10:20 AM Total Views:  244
View Complete with Replies




Related Messages:

RadioButtons used to display unique images..images are not showing.   (141 Views)
Hi I have been having some trouble getting my images to display. I decided to try and create a java program that used radio buttons to display an image ..problem is the images will not display. I am using Eclipse and there are no red tag errors in my code ..so I am not sure what I am doing wrong. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class RadioPics extends JFrame{ private JLabel pic; private Icon[] pics = {new ImageIcon (getClass().getResource("boat.png")), new ImageIcon (getClass().getResource("sophie.png")), new ImageIcon (getClass().getResource("ducks.png")), new ImageIcon (getClass().getResource("mcats.png"))}; private JRadioButton bo; private JRadioButton sd; private JRadioButton du; private JRadioButton mc; public RadioPics (){ super("PICK AN IMAGE"); setLayout(new FlowLayout()); bo = new JRadioButton("Desert Boat", true); sd = new JRadioButton("Sophie Dahl", false); du = new JRadioButton("Ducklings", false); mc = new JRadioButton("Meerkats", false); add(bo); add(sd); add(du); add(mc); ButtonGroup group = new ButtonGroup(); group.add(bo); group.add(sd); group.add(du); group.add(mc); bo.addActionListener(new ActionHandler(pics[0])); sd.addActionListener(new ActionHandler(pics[1])); du.addActionListener(new ActionHandler(pics[2])); mc.addActionListener(new ActionHandler(pics[3])); } private class ActionHandler implements ActionListener{ private Icon jay; public ActionHandler(Icon i){ jay = i; } public void actionPerformed(ActionEvent e) { if(e.ACTION_PERFORMED==ItemEvent.SELECTED) pic=new JLabel(jay); add(pic); } } } main class: import javax.swing.JFrame; public class RadioPicsMain { public static void main(String[] args) { RadioPics rp = new RadioPics(); rp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); rp.setSize(700, 700); rp.setVisible(true); } }
Swing doubt. not able to display pic on swing frame   (166 Views)
package com.rajiv; import java.awt.Graphics; import java.awt.Image; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; import org.apache.log4j.Logger; public class MyDrawPanel1 extends JPanel{ private static final Logger logger = Logger.getLogger(MyDrawPanel1.class); public void paintComponent(Graphics g) { Image image = new ImageIcon("cat.png").getImage(); boolean b = g.drawImage(image, 3, 4, this); } public static void main(String[] args) { JFrame frame = new JFrame(); MyDrawPanel1 panel = new MyDrawPanel1(); frame.getContentPane().add(panel); frame.setSize(300, 300); frame.setVisible(true); frame.repaint(); } }
GUI design advice needed for window displaying an image   (168 Views)
I have a tool (class) pretty well completed which allows a user to navigate through a possibly long list of our unique image files and choose one to display in a separate window. I need the user to be able to sequentially choose more than one so that they may be compared. I don't really want to keep track of multiple windows in the tool. The class is named, for now, ImageWindow.java. I expect the displayed image window to have a status bar and a JPanel just below the title bar to display a line of image statistics. I want a popup menu (mouse right click on the image) and the ability to get the mouse position over the image so that I may display the raw data value. We will have three or 4 sizes of images with the smaller ones needing to be zoomed in and the larger zoomed out. I'm still leaning Java and am especially new to GUI code. I'm not sure exactly how to proceed at this point. I'll have data that cannot be static, I think. Should the ImageWindow extend JPanel, implement MouseMotionListener, and have a main This would be similar to the example I found. Should I use a different structure
How do I cycle through an array of strings and display them one at a time when JButton is clicked   (149 Views)
all, I am a 42 year old computer science major but only two years in so I still have much to learn. I have pulled some strings from a text file and loaded them into an array. What is the best way to have each string displayed every time the next question button is pushed I am displaying it into a Text Field box, is this what would normally be used or is there a box better suited for this purpose I was planning on doing basically the same thing in the program with a file full of jpg's, but was hoping to make them display in the same window each time a new question was brought up. Any thoughts, suggestions, or flat out help would be appreciated,
Problem displaying the TEXT Vertically in a JLabel   (102 Views)
Hi...Guys Could anyone please, let me know the procedure, with the help of which the text can be displayed vertically in a JLabel.....
Read content of a csv file and display in Excel Format in Swing application   (95 Views)
Guys, Does anybody know how to display the content of a csv file in the excel format with dropdowns and few extra added features in a Swing ( Desktop application ) even though the Microsoft Excel sheet is not installed. Would any api's available for the requirement
display data from a JComboBox from one JFrame to another   (167 Views)
, I have two windows, one where the user selected an element in a JComboBox and the other where I want to retrieve the value of this JComboBox and display it in a label. The problem is: how to retrieve the value of the text in the JComboBox and send it to my second window I have two class in the same package : fenetre1.java public JLabel labelR ; . . . fenetre1(){ . . String g=comboBox1.getSelectedItem().toString(); String a=comboBox2.getSelectedItem().toString(); String v=comboBox3.getSelectedItem().toString(); labelR1.setText(g); . . . }
I need help to display images on the panel by clicking   (152 Views)
This is my FlowerImage class: import javax.swing.*; public class FlowerImage { java.awt.Point _location; java.awt.Image _fImage; public FlowerImage(java.awt.Image image, java.awt.Point loc){ _fImage = image; _location = loc; FlowerImage flower = new FlowerImage(new ImageIcon("daffodil1.gif").getImage(),loc); } public java.awt.Point getLoc() {return _location;} public int getX() { return (int)_location.getX();} public int getY() {return (int) _location.getY(); } public java.awt.Image getImage() {return _fImage; } }
Reading the values of csv file and displaying it in AWT table   (130 Views)
I want to read the values of csv file and display that in AWT table when start button is pressed. Pressing stop button should stop reading the values. Reset button must be used to clear the table. I am new to AWT. Here is what i have tried. package AWTTable; import java.awt.*; import java.sql.*; import java.util.*; import javax.swing.*; import java.awt.event.*; import java.io.BufferedReader; import java.io.FileReader; /** * * @author Admin */ public class AWTTableUpdate { public static void main(String[] args) { Frame f = new Frame(); Label label = new Label("Date and Time "); Label label1 = new Label(" Name"); Label label2 = new Label("contents"); final Vector columnNames = new Vector(); final Vector data = new Vector(); final TextField text = new TextField(20); Button b = new Button("Start"); Button b1 = new Button("Stop"); Button b2 = new Button("Reset"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { String strFile = "c:/companylist.csv"; BufferedReader br = new BufferedReader(new FileReader(strFile)); String strLine = ""; StringTokenizer st = null; int lineNumber = 0, tokenNumber = 0; ArrayList arrayList = new ArrayList(); while ((strLine = br.readLine()) != null) { lineNumber++; st = new StringTokenizer(strLine, ","); while (st.hasMoreTokens()) { tokenNumber++; arrayList.add(st.nextToken()); tokenNumber = 0; } Object[] elements = arrayList.toArray(); Scanner input = new Scanner(System.in); System.out.print("Enter Ticker symbol"); } }catch (Exception e1) { System.out.println("Exception while reading csv file: " + e1); } JTable table = new JTable(data, columnNames); JScrollPane scrollPane = new JScrollPane(table); JFrame frame = new JFrame(); frame.add(scrollPane); frame.setVisible(true); frame.pack(); frame.repaint(); } }); Panel p = new Panel(new GridLayout(6, 6)); p.add(label); p.add(label1); p.add(label2); // p.add(text); p.add(b); p.add(b1); p.add(b2); f.add(p); f.setVisible(true); f.pack(); } }
Hiding the actual data values in the DataModel when displaying with JTable   (123 Views)
I have an application that keys off the values in a column in my table. A new requirement is that the GUI have an option to change the units in that column. One thought I had to satisfy this new requirement was to modify the cell editor and cell renderer. So if I did a getValue on the table, I'd always get the same value, but the user would see values scaled in the units they requested. The code is below. It's not my only choice. I could also modify getValue and setValue to do the conversion. Or I could modify all the classes and methods that currently expect specific units. I like the idea of handling the conversion early, but I am wondering if anyone has comments on the 'best practices' way of handling this. And also, if my code is not right, suggestions to improve it. If you run it, just type a number in the cell. Set Scale doubles the scale every time you press it, while Press Here gives the value in the model. import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; import java.text.*; import javax.swing.border.*; import java.awt.Color.*; class TableHideValues extends JFrame { String[] tableHeaders = {"Double"}; Object[][] tableData = new Object[1][tableHeaders.length]; MyTableModel modelMe; JTableHeader headerMe; JTable tableMe; JButton buttonMe; JButton scaleMe; JPanel panelMe; double scale = 1.00; public TableHideValues() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setContentPane(new MainPanel()); pack(); setSize(240,120); setVisible(true); } private class MainPanel extends JPanel { public MainPanel() { super(new BorderLayout()); modelMe = new MyTableModel(tableData, tableHeaders ); tableMe = new JTable(modelMe); headerMe = tableMe.getTableHeader(); TableColumn dcol = tableMe.getColumnModel().getColumn(0); dcol.setCellEditor(new DoubleCellEditor()); dcol.setCellRenderer(new DoubleCellRenderer()); buttonMe = new JButton("Press Here"); buttonMe.addActionListener(new buttonListener()); scaleMe = new JButton("Set Scale"); scaleMe.addActionListener(new scaleListener()); panelMe = new JPanel(); panelMe.add(buttonMe); panelMe.add(scaleMe); add(BorderLayout.NORTH, headerMe); add(BorderLayout.CENTER, tableMe); add(BorderLayout.SOUTH, panelMe); } } class buttonListener implements ActionListener { public void actionPerformed(ActionEvent e) { System.out.println("Model value: " + modelMe.getValueAt(0,0)); } } class scaleListener implements ActionListener { public void actionPerformed(ActionEvent e) { scale = scale * 2; modelMe.fireTableDataChanged(); } } public static void main(String[] args) { TableHideValues window = new TableHideValues(); } class MyTableModel extends DefaultTableModel { public MyTableModel(Object rowData[][], Object columnNames[]) { super(rowData, columnNames); } @Override public Class getColumnClass(int col) { return Double.class; } } class DoubleCellRenderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent( JTable table, Object value, boolean selected, boolean focus, int row, int col) { Component renderComponent = super.getTableCellRendererComponent( table, value, selected, focus, row, col); super.setHorizontalAlignment( SwingConstants.RIGHT ); NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(0); if (value != null) { value = (Double) value * scale; value = nf.format(value); super.setValue(value); } else { super.setValue(""); } return renderComponent; } } class DoubleCellEditor extends DefaultCellEditor { private Double value; private final JTextField textField; private final NumberFormat nf = NumberFormat.getInstance(); public DoubleCellEditor() { super(new JTextField()); textField = (JTextField) getComponent(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(0); textField.setHorizontalAlignment(JTextField.RIGHT); textField.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { textField.setText(nf.format(value.doubleValue())); textField.setCaretPosition(0); } @Override public void focusLost(FocusEvent e) { } }); } public boolean stopCellEditing() { String s = (String)super.getCellEditorValue(); if ("".equals(s)) { super.stopCellEditing(); } try { value = Double.valueOf(s); } catch (Exception e) { textField.setBorder(new LineBorder(Color.red)); return false; } return super.stopCellEditing(); } public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int col) { try { this.value = (Double) value * scale; } catch (Exception e) { this.value = (Double) value; } textField.setBorder(new LineBorder(Color.black)); return super.getTableCellEditorComponent( table, value, isSelected, row, col); } public Object getCellEditorValue() { try { value = (Double) value / scale; } catch (Exception e) { value = (Double) value; } System.out.println("Editor value: " + value); return value; } } }
Cant get JDialog to display   (177 Views)
Hi I have a problem that I have been strugling with for the last few days and just cant sort it out. I have a program that has a main window when if a user clicks on a buton on that window a JDialog box should come up where a user can enter a date. Whenever I try to click on that button the outline of the JDialog comes up on screen with the window title and window buttons but there is nothing inside it. I have tryed just displaying the JDialog its self and everything comes up ok. I just cant get it to work when I click the button on the other window. I dont know what code is causing it so I have included the constructor for the JDialog. public CallenderGUI() { this.setSize(345, 250); this.setLocation(40, 40); this.setTitle("Select date"); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.contentPane = getContentPane(); this.monthYearPanel = new JPanel(); this.daysOfMonthPanel = new JPanel(); this.contentPane.add(monthYearPanel, BorderLayout.NORTH); this.contentPane.add(daysOfMonthPanel, BorderLayout.CENTER); for (int i = 0; i < NUMBER_OF_DAYS; i++) { daysOfMonthArray[i] = new JButton(); } monthList = new JComboBox(); for (int i = 0; i < MONTHS.length; i++) { monthList.addItem(MONTHS[i]); } yearList = new JComboBox(); for (int i = 2005; i < 2026; i++) { yearList.addItem(i); } monthYearPanel.setLayout(new GridLayout(1, 2)); daysOfMonthPanel.setLayout(new GridLayout(0, 7)); monthYearPanel.add(monthList); monthYearPanel.add(yearList); daysOfMonthPanel.add(new JLabel(" S")); daysOfMonthPanel.add(new JLabel(" M")); daysOfMonthPanel.add(new JLabel(" T")); daysOfMonthPanel.add(new JLabel(" W")); daysOfMonthPanel.add(new JLabel(" T")); daysOfMonthPanel.add(new JLabel(" F")); daysOfMonthPanel.add(new JLabel(" S")); for (int i = 0; i < NUMBER_OF_DAYS; i++) { daysOfMonthPanel.add(daysOfMonthArray[i]); daysOfMonthArray[i].addActionListener(new ButtonWatcher()); } monthList.addItemListener(new MonthListListener()); yearList.addItemListener(new YearListListener()); currentMonth = getCurrentMonth(); monthList.setSelectedItem(currentMonth); currentYear = getCurrentYear(); yearList.setSelectedItem(currentYear); currentDay = getCurrentDay(); selectedDate = new GregorianCalendar(); selectedDate.set(currentYear, getCurrentMonthInt(currentMonth), currentDay); dateSelected = false; loadNumOnButtons(currentMonth, currentYear); this.pack(); setVisible(true); }
displaying data from database   (108 Views)
hi , i have created my first gui projects interface. the interface consists of a few combo boxes and buttons. now what i want is a simple tutorial that teaches me how to retrieve information form a back end database using the values input by the user into the interface. any suggestions and i was also wondering where i can learn how to display a new window on clicking a button and also how to display new contents in an already visible window i.e wiping off entire components being displayed on a window and replacing them with new components.
tree display   (91 Views)
all, I want to know how to display tree node values in another jscrollpane using jsplitpane. for this i need to add tree selection listner, so that when i click on node its contents or child nodes should be displayed in second jscroll pane how to do that
pop-up frames display for a few seconds when i run my programs outside the IDE   (98 Views)
ranchers!!! I really need your help on this. When i ever i write a program and run it outside the IDE (i use netbeans 6.9.1), the program runs perfectly, but when i install JDK 6 or 7 on a pc that did not previously have java and run my program, the pop-up frames such as JFileChooser or JOptionPane only show for a couple of seconds (approximately 7 to 9 seconds) then they close themselves and choose the default option without any user input. I need y'all to help me out or give me suggestions on what to do or what i'm doing wrongly. NB: I use 'javaw.exe' under the '/bin' directory of the JRE to execute the program since the 'java.exe' only brings out a console for2 seconds then does nothing.
Swing elements not displaying properly   (170 Views)
! I am new to Java, having taken an online course in it. I am trying to write a very simple program. I'm starting with the UI. I have four elements: a label, a combo box, another label, and a button. When I run the program, I see the second label (element #3) followed by the combo box (element #2). The other elements do not display. I have not set a layout (I have tried a couple, but I am obviously doing it wrong as I get errors.) The relevant code is quoted here (do I need to include more) and a picture of the app's display is attached. Are my mistakes obvious to anybody
Buttons not displaying till I mouseover them?   (132 Views)
Hi folks, I'm new to the forums and to Java. I just finished reading through Head First Java, which was pretty good at giving me a base, as I look into more advanced/in-depth books. I set out to make a Tic-tac-toe (Cross and Noughts) game to test my learning so far. While things have gone pretty well so far, I am absolutely stumped by my current issue. When I compile and run the code, the Grid of buttons that I generate do not appear. However, if I mouse over the window, they seem to then get refreshed/repainted. I cannot for the life of me figure out why this is happening. From Googling the issue, it seems this is either an issue with the layout manager or related to a thread conflict with the GUI (http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html) I would really appreciate if someone could help explain why this is happening and what I should do to fix the issue. Also, any other suggestions for my code/best practices would be most appreciated. I'm listing out the code for the game class and the button class. import java.awt.event.*; import javax.swing.*; import java.awt.*; import java.util.*; public class CrossNoughtsGame { private JFrame frame; private JPanel mainPanel; private ArrayList buttonList = new ArrayList(); private boolean isX = true; private int moveCount = 0; private int dimension = 3; public void setupGame() { // Initialize Game GUI frame = new JFrame("Tic-Tac-Toe Game - Warning! Alpha Prototype"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GridLayout grid = new GridLayout(dimension, dimension, 0, 0); mainPanel = new JPanel(grid); //mainPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); for (int x = 0 ; x < dimension; x++ ) { for (int y = 0 ; y < dimension; y++ ) { CNButton tempButton = new CNButton(x, y); tempButton.addActionListener(new clickListener()); //tempButton.setPreferredSize(new Dimension(25,25)); buttonList.add(tempButton); mainPanel.add(tempButton); } } frame.getContentPane().add(mainPanel); frame.setSize(300,300); frame.setVisible(true); } public boolean isGameOver() { // Checks state of all CNButton elements to see if game is over. Prints appropriate message return true; } private class clickListener implements ActionListener { // Listener Class for callback from CNButton elements // Sets state of button correctly, displays X or O public void actionPerformed(ActionEvent e) { CNButton clickedButton = (CNButton) e.getSource(); // Source Button that fired event System.out.println("Button Co-ordinates: " + clickedButton.getX() + ", " + clickedButton.getY()); if (clickedButton.getValue() == 0) { if ( isX ) { clickedButton.setText("X"); clickedButton.setValue(1); } else { clickedButton.setText("O"); clickedButton.setValue(-1); } moveCount++; isX = !isX; clickedButton.setEnabled(false); // Disable button from future clicks isGameOver(); } } } public static void main(String [] args) { CrossNoughtsGame GameGUI = new CrossNoughtsGame(); GameGUI.setupGame(); } }
displaying the file name of a pendrive in a text area by clicking a button   (161 Views)
hi .... my project is on pen drive where deer l b a display screen and with blue tooth functionality... i have a code which is displaying the list name but not in the text area... please help me out in this .... import java.io.File; import java.awt.*; import java.awt.event.*; public class DirectoryReader { static int spc_count=-1; static void Process(File aFile) { spc_count++; String spcs = ""; for (int i = 0; i < spc_count; i++) spcs += " "; if(aFile.isFile()) System.out.println(spcs + "[FILE] " + aFile.getName()); else if (aFile.isDirectory()) { System.out.println(spcs + "[DIR] " + aFile.getName()); File[] listOfFiles = aFile.listFiles(); if(listOfFiles!=null) { for (int i = 0; i < listOfFiles.length; i++) Process(listOfFiles[i]); } else { System.out.println(spcs + " [ACCESS DENIED]"); } } spc_count--; } public static void main(String[] args) { String nam = "H:/"; File aFile = new File(nam); // textArea.add(Process(aFile)); Button b; Frame frame=new Frame("Text Frame"); TextArea textArea=new TextArea("hello!Welcome to BLUE PEN world",4,30); frame.add(textArea); frame.setLayout(new FlowLayout()); frame.setSize(250,250); frame.setVisible(true); textArea.setEditable(true); frame.add(b = new Button(""),BorderLayout.CENTER); frame.add(b = new Button("ok"),BorderLayout.NORTH); frame.add(b = new Button("v"),BorderLayout.EAST); frame.add(b = new Button("^"),BorderLayout.WEST); frame.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); } }
tray icon is not displaying   (84 Views)
I have a small program, where i add a tray icon (with ico image) to the system tray and I am adding some menu-item to it etc. I can see the space in the system tray. I can see all the menu-items in it. when i click/right click. But the icon image is not showing. Earlier i assumed that, there is a possiblity that the ico image size is big and hence it is not showing. So i replaced it with small .ico image. but still it is not showing. can you please help me in the same Image image = icon.getImage(); System.out.println("image initialez"); TrayIcon ti = new TrayIcon(image, "Transformation Server Monitor",menu); System.out.println("tray icon initialez"); SystemTray tray = SystemTray.getSystemTray(); try { tray.add(ti); System.out.println("tray icon added"); //$NON-NLS-1$ } catch (AWTException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
JLabels not displaying   (87 Views)
I've got some JLabels that I add to a JPanel within a JApplet, first when the JApplet loads the JLables do not display. If I resize a little the JLabels display, if I continue making the JApplet larger then the JLabel moves to the left and you can see part of the JLabel earlier underneath the latest display of it. Looks as though the JLabel keeps reprinting but overwriting the older copies of itself. How can I refresh the page, clear the page each time
using of Next and Previous button to display database values   (165 Views)
Sir, i am trying to fetch database values and display them in a JTable. I have used DefaultTableModel and somehow managed to display data. I have two JButtons PREVIOUS and NEXT, which need to play their own role. i am maintaining a database table with time as a field. i have corresponding to different times, different values for different fields. i need to fetch those values and display in JTable, which is attached to a scrollpane. now my problem is that how to perform the next and previous method for the respective NEXT and PREVIOUS JButtons. Can anyone help me to get out of it. Please give me some suggestion regarding this... And at the same time is it a good step of using DefaultTableModel whether i need to use AbstractTableModel Actually i did not get the full idea of using AbstractTableModel. can you please provide me some suitable examples which is using AbstractTableModel and fetching Database values, not hardcoded..... Thank you in advance.