Tracking when a JComponent is visible


ComponentListener doesn't provide notification when, say, a frame is minimized or closed, just when setVisible() is called I presume (I haven't testing hiding a component behind something).

That actual problem, for the record, is that I have an animated component and I want it to be able to stop the animation thread if, say, the frame it's being displayed in is disposed(). Is there a way to track this
Posted On: Tuesday 23rd of October 2012 11:31:22 PM Total Views:  251
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




how to calculate cpu/memory utilizing by jcomponents/jpanels/Jframe?

I create 1 Jframe in that 1 big jpanel fitted to that JFrame. In that jpanel i create array of jpanels(small) say n numbers...n=5,6,7,,9...up to...99. size (25,25) Now i want print statement which shows cpu/memory utilized by each panel/component...
VIEWS ON THIS POST

195

Posted on:

Tuesday 25th September 2012
View Replies!

JList set element visible

First, let me describe a couple of restrictions that I have in my environment and the problem that I'm having. So first the restrictions, I'm working on an airgapped environment so everything here has to be hand jammed in by me. There is no way for me to just copy paste my working code in so there may be little typos here and there. Second some of the systems that I'm running this one are fairly archaic, so the newest version of java that I'm using is 1.4 and it's not possible for me to put in backports of new java apis. Now for the problem, I'll post the code below this description. I'm making a gui frontend that has a JList in a tabbed pane and another pane that contains a list of buttons. I want these buttons to act like filters so that when they are pressed the jlist only shows items related to that button. I need to maintain the integrity of the elements in the background so that I can set them to visible and invisible at will. I've thought about extending the buttons and backing them with the list, but that's pretty computationally expensive to do every time there is an update. Anyway, here's some code. public class EventWindow extends JFrame { private JPanel systemPanel = new JPanel(); private JList list; private DefaultListModel model; private Logger log = Logger.getLogger(this.Class().getName()); private double diffThresh = 6.5; private JButton clear = new JButton("Clear "); private JButton remove = new JButton("Remove"); private JButton saveError = new JButton("Save Selected"); private ActionListener clear = new Clear(); private DiceCoefficient dice = new DiceCoefficient(); private Map sysButtons = Collections.synchronizedMap(new HashMap()); private GridBagConstraints c = new GridBagConstraints(); private final Insets insets = new Insets(2,2,2,2); private ActionListener systemListener = new SystemSelected(); private String systemSelected = ""; private int x = 0; private int y = 0; private JTabbedPane tabPane = new JTabbePane(); private boolean allSelected = true; public void draw() { this.setSize(400,500); c.insets = insets; this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create the list to display new messages as they come in model = new DefaultListModel(); model.ensureCapacity(300); list = new JList(model); list.setCellRenderer(new TextCellRenderer()); list.setDoubleBuffered(true); list.setAutoScrolls(true); this.getContentPane().setLayout(new GridBagLayout()); JPanel displayPanel = new JPanel(); displayPanel.setLayout(new GridBagLayout()); JScrollPane buttonScroller = new JScrollPane(systemPanel); systemPanel.setLayout(new GridBagLayout()); JScrollPane listScroll = new JScrollPane(list); c.fill = GridBagConstraints.BOTH; c.weightx = 0.5; c.weighty = 1; c.gridwidth = 3; c.gridx = 0; c.gridy = 0; displayPanel.add(listScroll, c); c.weightx = 0.5; c.weighty = 0; c.gridwidth = 1; c.gridx = 0; c.gridy = 1; c.fill = GridBagConstraints.NONE; displayPanel.add(remove, c); c.gridx =1; displayPanel.add(clear, c); c.gridx = 2; displayPanel.add(saveError, c); c.weighty = 0.9; c.gridx = 1; c.gridy - 0; tabPane.addTab("Event Window", displayPanel); c.weighty = 0; c.gridx = 0; c.gridy = 0; tabPane.addTab("Systems List", buttonScroller); c.gridHeight = 1; c.fill = GridBagConstraints.HORIZONTAL; clear.addActionListener(clear); remove.addActionListener(clear); saveError.addActionListener(clear); c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; EventWindow.this.getContentPane().add(tabPane, c); c.weightx = 0.5; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.FIRST_LINE_START; } //Public accessor that adds an event to the AWT event queue public syncronized void updateGui(final ListItem li) { SwingUtilities.invokeLater(new Runnable() { updateEventArea(li); }); notify(); } //Method ran to start the process of updating the gui with new information private synchronized void updateEventArea(ListItem li) { deDuplicate(li); processButton(li);//Create or update a button this.validateTree(); notify(); } private void deDuplicate(ListItem li) { //Logic goes here to go through all the list items and use the dice algorithm to remove duplicate messages and append the new model.addElement(li); } private void processButton(ListItem li) { String source = li.getSource(); JButton foundButton = (JButton)sysButtons.get(source); if (foundButton != null) { int numErrors = getSystemCount(source);//Current number of uncleared messages String numErrorsString = Integer.toString(numErrors); int paran = foundButton.getText().indexOf("(");//Get the location of the paran in the button text String newButtonText = foundButton.getText().substring(0,paran) + "(" + numErrorString + ")"; foundButton.setText(newButtonText); } else { JButton button = new JButton(source + "(1)"); sysButtons.put(source, button); button.addActionListener(systemListener); if (x ==5) {x = 0; y++} c.gridx = x; c.gridy = y; systemPanel.add(button, c); x++; } } private int getSystemCount(String source) { int num = 0; for (int i = 0; i < model.size(); i++) { String tracked = ((ListItem)model.get(i)).getSource(); if (source.equals(tracked){ num++; } } return num; } private class Clear implements ActionListener { public void actionPerformed(ActionPerformed e) { if (e.getSource().equals(clear) { if (allSelected) { model.clear(); systemPanel.remove(); sysButtons.clear(); } else { String source = null; for (int i = 0; i < model.getSize(); i++) { ListeItem li = ((ListItem)model.getElementAt(i); source = li.getSource(); if (source.equals(selectedSystem)) model.removeElement(li); } } reLayout(); } else if (e.getSource().equals(remove)) { //Go through the model and remove all the selected Items if (list.getSelectedIndices().length > 0) { int tmp[] = list.getSelectedIndices(); int selected[] = list.getSelectedIndices(); for (int i = tmp.length -1; i >=0; i--) { selected = list.getSelectedIndices(); ListItem li = (ListItem)model.get(selected[i]); model.removeElement(li); } } } /*Go through every button and find lines in the tracker *that are associated with each button. Keep a count * of all these systems, then update the text on the button * to reflect the count of currently pending erros. */ Object keys[]=sysButtons.keySet().toArray(); for (int i = 0; i < key.length; i++) { String source = (String)keys[i]; int num = getSystemCount(source); if (num ==0) { JButton button = (JButton)sysButtons.get(source); systemPanel.remove(button); sysButtons.remove(source); } else { JButton button = (JButton)sysButtons.get(source); button.setText(source + "(" + Integer.toString(num) + ")"; } reLayout(); } } } //The next method lays all the sysButtons out in a nice looking grid private void reLayout() { //Reset x and y x = 0; y = 0; c.fill = GridBagConstraints.HORIZONTAL; systemPanel.remove();//Clear the panel out to be re-populated Object buttons[] = sysButtons.keySet().toArray(); for (int i = 0; i < buttons.length; i++) { if (x > 5) { x = 0;//Start at first column y++;//Start new row c.gridx = x; c.gridy = y; systemPanel.add(((JButton)sysButtons.get((String)buttons[i])), c); x++; } else { c.gridx = x; c.gridy = y; systemPanel.add(((JButton)sysButtons.get((String)buttons[i])), c); x++; } } systemPanel.reValidate(); } /* *Here is where I want the magic to happen. I want to keep all the ListItems that *are values of the model elements, but only show the ones that match the variable *selectedSystem. I've tried setting the setVisible() boolean to false for all the *elements that didn't match, but that didn't work and I'm kinda at a loss here. */ private class SystemSelected implements ActionListener { public void actionPerformed(ActionEvent e) { JButton button = (JButton)e.getSource(); int paran = button.getText().indexOf("("); selectedSystem = button.getText().substring(0,paran); allSelected = false; tabPane.setSelectedIndex(0); } } }
VIEWS ON THIS POST

72

Posted on:

Wednesday 26th September 2012
View Replies!

JSplitter divider location tracking

Hi all I want to take the divloaction when user Drag the Divder location to some place Which is the best listner and Mouse dragged event is not happening
VIEWS ON THIS POST

58

Posted on:

Monday 1st October 2012
View Replies!

Refreshing contents of a ComboBox while it is still visible

I have implemented a ComboBoxModel that is populated based on data from a database: public abstract class DatabaseComboBoxModel extends AbstractListModel implements ComboBoxModel { public static final String CHOOSE_ONE = "(Choose one)"; private SQLUtil sqlUtil; private List list = new ArrayList(); private int selectedIndex = -1; /** * Creates a new instance of DatabaseComboBoxModel. */ public DatabaseComboBoxModel(SQLUtil sqlUtil) throws SQLException { this.sqlUtil = sqlUtil; //this.refreshModel(); } public void refreshModel() throws SQLException { this.list.clear(); this.sqlUtil.setSQL(this.getSQLString()); this.setSQLParameters(this.sqlUtil); ResultSet rs = this.sqlUtil.executeQuery(); while (rs.next()) { DatabaseRecord data = this.getDatabaseRecord(rs); this.list.add(data); } } protected abstract String getSQLString(); protected abstract void setSQLParameters(SQLUtil sqlUtil) throws SQLException; protected abstract DatabaseRecord getDatabaseRecord(ResultSet rs) throws SQLException; public Object getElementAt(int param) { if (param == 0) { return CHOOSE_ONE; } else { return list.get(param - 1); } } public Object getSelectedItem() { if (this.selectedIndex == -1) { return CHOOSE_ONE; } else { return this.list.get(this.selectedIndex); } } public int getSize() { return this.list.size() + 1; } public void setSelectedItem(Object obj) { if (CHOOSE_ONE.equals(obj)) { this.selectedIndex = -1; } else { this.selectedIndex = this.list.indexOf(obj); } } public abstract class DatabaseRecord { private int id; public DatabaseRecord(int id) { this.id = id; } public int getID() { return this.id; } public abstract String toString(); } }
VIEWS ON THIS POST

121

Posted on:

Wednesday 3rd October 2012
View Replies!

System Tray - double click icon to set visible

I have this code working just fine, one option I want is to use a double-click on the icon in the system tray to set the application visible again. I am thinking of using a mouse listener but not sure where I would put it or would I use a window listener
VIEWS ON THIS POST

92

Posted on:

Wednesday 17th October 2012
View Replies!

Invisible Buttons still visible

In our application ,(Talking about applet )when we press a button on our main screen( that is a frame), another frame is open. We have to disable the buttons on previous frame and we have achieved this but the problem is ,the disabled buttons of previous frame are visible on the current frame, although we set their visibility false , that is very annoying and not only the buttons but also the other fields are behaving in same way that is they are visible on current frame, they all are not visible at a same time ,the one which was pressed is displayed on the current screen.For instance , if we press "ADD" button and the next frame is appeared on that press,then the "ADD button" would be visible on the current screen but if we press "modify" button then this time "modify" button would be visible on screen. this visibility is not actually the "visibility".it is some sort of image/water mark.As soon as we click anywhere on current frame,this visibility is no longer sustained. How can we fix this bug How can we stop buttons and fields of previous frame to be seen on current frame One more thing this is not one program issue, we are facing this problem through out the application.
VIEWS ON THIS POST

55

Posted on:

Wednesday 17th October 2012
View Replies!

header color and the cursor double headed arrow in JTable is not visible

I am using NetBeans 6.7.1 In this desktop app after the user imports a file, the data is displayed in the JTable. Before the file is imported the JTable is setVisible(false) Once the user selects a file to open the code is below tableScrollPane.setVisible(true); jTable1.setVisible(true); DataFileTableModel model = new DataFileTableModel(dataList); jTable1.setModel(model); jTable1.getTableHeader().setBackground(Color.blue); jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); //HERE is the code to assign the width of the column equal to the length of the header text
VIEWS ON THIS POST

106

Posted on:

Wednesday 17th October 2012
View Replies!

How to make label visible

I have created a radio button group with two buttons in NetBeans, and I would like some text to show up when the button is chosen and become greyed out when it is not chosen. I have tried adding the code: private void rdoNoFracActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: lblIWillChoose.setVisible(true); lblIWillChoose.setEnabled(true); lblUserFrac.setEnabled(false); lblUserFrac.setVisible(false); }
VIEWS ON THIS POST

107

Posted on:

Wednesday 17th October 2012
View Replies!

Why Glass Pane becomes visible when resizing JInternalFrame?

, I've created a JFrame with JDesktop and one JInternalFrame on it. I've also added a glasspane (which draws a black circle only) to JFrame - it's invisible by default but when I resize JInternalFrame it shows up.. is this correct behavior Why it is visible only when I resize and diappears when I release mouse button after resize How I can make it invisible when resizing JInternalFrame (Is removing JFrame's glasspane only solution)import java.awt.Graphics; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JPanel; public class RunMe extends JFrame { public RunMe() { this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setBounds(10, 10, 800, 600); JDesktopPane desktop = new JDesktopPane(); JInternalFrame testJIF = new JInternalFrame("test", true, true, true, true); testJIF.setBounds(10, 10, 100, 100); desktop.add(testJIF); testJIF.setVisible(true); this.add(desktop); this.setGlassPane(new MyGlassPane()); this.setVisible(true); } private class MyGlassPane extends JPanel { public MyGlassPane() { this.setOpaque(false); } @Override protected void paintComponent(Graphics g) { g.fillOval(0, 0, 100, 100); super.paintComponent(g); } } public static void main(String[] args) { new RunMe(); } }
VIEWS ON THIS POST

91

Posted on:

Wednesday 17th October 2012
View Replies!

How to make popup invisible

If I run the following application and then right-click on the application, a popup menu will show up. If I move mouse outside the frame (I try to make JComponent visible so that I can move mouse outside JComponent, but I cannot make it happen), popup menu is still visible. I try to add the following to mouseExited method: popupMenu.setVisible(false); or add the following to let popup listen to mouse listener: popupMenu.addMouseListener(new MouseListener(){ public void mouseExited(final MouseEvent e) { System.out.println("Mouse Exited..."); popupMenu.setVisible(false); //line added } public void mouseEntered(final MouseEvent e) { System.out.println("Mouse Entered..."); } public void mousePressed(final MouseEvent e) { System.out.println("Mouse pressed..."); } public void mouseReleased(final MouseEvent e) { } public void mouseClicked(final MouseEvent e) { System.out.println("Mouse Clicked..."); } });
VIEWS ON THIS POST

95

Posted on:

Thursday 18th October 2012
View Replies!

Empty JPanel's aren't invisible

I've been trying to get JTextFields onto my JFrame using the GridBagLayout. I've managed to do this. I was recommended to use empty JPanels with weightx / weighty set as 1, in order to space things out like I wanted. This seemed to work until I put a jpg image onto my frame, and I noticed 2 small grey(same colour as regular background) squares in the centres of the regions where I placed the 2 empty JPanels. Is there anyway of getting rid of these squares, or doing it some other way\t
VIEWS ON THIS POST

80

Posted on:

Thursday 18th October 2012
View Replies!

How do I make two frame visible simaltenously

Hi! I am having two frame frm1 and frm2. fr1 contains one button and textarea. frm2 contains combo box that contains some text. When I clicks on button frm2 gets visible but frm1 gets mininized, I want to make both the frame visible simaltaneously so that I can insert some text in textarea of frm1 by selectin text from combo box of frm2. Just like modeless dialog box. Is it possible, if yes then how
VIEWS ON THIS POST

73

Posted on:

Thursday 18th October 2012
View Replies!

Make table column invisible

Hi , The following code make the column invisible, but also removes it from the model. table.getColumnModel().removeColumn(table.getColumnModel().getColumn(0)); How can I make the column invisible, but *not* remove it from the model, because I need to obtain the data from the invisible column later on. Also, this is not working, since when I increase column width by dragging I can see some dots and the coumn becomes partially visible: TableColumn idClmn= table.getColumn("Property id"); idClmn.setMaxWidth(0); idClmn.setMinWidth(0); idClmn.setPreferredWidth(0);
VIEWS ON THIS POST

80

Posted on:

Thursday 18th October 2012
View Replies!

Printing invisible JTable containing JTables - problem

I am trying to print an invisivle JTable that contains inner JTables (nested). The outer JTable prints as it should, but for some reason the inner JTables header is never printed, even though everything else of the inner JTables is printed as it should, and that is where the problem is. I have tried everything I can think of without solving it. I would be happy if someone could help me with this. Thatnks in advance for any help. In my code the table is made visible after it is printed to show what it should be like. Here's my example code: import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.print.PrinterException; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableColumnModel; import javax.swing.table.DefaultTableModel; import javax.swing.table.JTableHeader; import javax.swing.table.TableColumn; public class TestNestedJTable2 extends JFrame{ private static final long serialVersionUID = -722808327091366767L; private JTable mainTable; private JTable leftTable; private JTable rightTable; private Object[][] tableList; private Container container; private String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"}; private Object[][] data = { {"Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false)}, {"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)}, {"Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false)}, {"Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true)}, {"Philip", "Milne", "Pool", new Integer(10), new Boolean(false)}, }; private String[] columnNames2 = {"", "Last Name", "Group", "Year"}; private Object[][] data2 = { {false, "Li", "Tiger", new Integer(1997), }, {false, "Roy", "Lion", new Integer(1996)}, {false, "Lee", "Dragon", new Integer(1989)}, {false, "Jones", "Lion", new Integer(1981)}, {false, "Lam", "Dragon", new Integer(1980)}, }; private String[] names = {"sdf", "sdf", "dfs"}; public TestNestedJTable2(){ container = this.getContentPane(); leftTable = new JTable(data, columnNames); rightTable = new JTable(data2, columnNames2); leftTable.getTableHeader().setVisible(true); rightTable.getTableHeader().setVisible(true); leftTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); leftTable.setSize(leftTable.getPreferredSize()); JTableHeader header = leftTable.getTableHeader(); header.setSize(header.getPreferredSize()); rightTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); rightTable.setSize(rightTable.getPreferredSize()); header = rightTable.getTableHeader(); header.setSize(header.getPreferredSize()); tableList = new Object[1][]; tableList[0] = new Object[3]; tableList[0][0] = leftTable; tableList[0][1] = rightTable; tableList[0][2] = "dfgfdg"; mainTable = new JTable(new DefaultTableModel(tableList, names)); TableColumn tc = mainTable.getColumnModel().getColumn(0); tc.setCellRenderer(new CustomTableCellRenderer(leftTable)); tc = mainTable.getColumnModel().getColumn(1); tc.setCellRenderer(new CustomTableCellRenderer(rightTable)); mainTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); DefaultTableColumnModel colModel = (DefaultTableColumnModel) mainTable.getColumnModel(); TableColumn col = colModel.getColumn(0); col.setPreferredWidth(leftTable.getSize().width + 2); col.setWidth(leftTable.getSize().width + 2); col = colModel.getColumn(1); col.setPreferredWidth(rightTable.getSize().width + 2); col.setWidth(rightTable.getSize().width + 2); mainTable.setRowHeight(leftTable.getPreferredSize().height+leftTable.getTableHeader().getPreferredSize().height+1); mainTable.setMinimumSize(mainTable.getPreferredSize()); mainTable.setSize(mainTable.getPreferredSize()); header = mainTable.getTableHeader(); header.setSize(header.getPreferredSize()); try { mainTable.print(JTable.PrintMode.FIT_WIDTH); } catch (PrinterException e) { // TODO Auto-generated catch block e.printStackTrace(); } container.add(new JScrollPane(mainTable)); setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); setSize(800,800); setVisible(true); } class CustomTableCellRenderer extends DefaultTableCellRenderer { private static final long serialVersionUID = 4415155875184525824L; JTable table; CustomTableCellRenderer(JTable table){ this.table=table; this.table.setOpaque(true); this.table.setAlignmentY(JTable.LEFT_ALIGNMENT); } @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { this.table=(JTable)value; this.table.setPreferredScrollableViewportSize(this.table.getSize()); JScrollPane jCrollPane = new JScrollPane(this.table); jCrollPane.setBorder(BorderFactory.createEmptyBorder()); jCrollPane.getViewport().setSize(new Dimension(this.table.getSize().width-1, this.table.getSize().height+16)); return jCrollPane; } } /** * @param args */ public static void main(String[] args) { new TestNestedJTable2(); } }
VIEWS ON THIS POST

124

Posted on:

Monday 22nd October 2012
View Replies!

Icons not visible in applet

Dear I have a created a JTree where every node has an icon. One class is that extends JPanel is being used for the tree, and everything works fine and the icons show correctly. However, when I create an instance of that class and add it to my Applet(which contains several other components), the icons are not visible. Anyone has any idea why Any suggestions will be appreciated.
VIEWS ON THIS POST

72

Posted on:

Monday 22nd October 2012
View Replies!

add component to a visible component

Hi , I want to add a component(subPanel) to a already visible component(mainJPanel). Here is my piece of code JPanel mainPanel=new JPanel(); mainPanel.setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS)); mainPanel.setPreferredSize(new Dimension(400,700)); mainPanel.setBackground(Color.PINK); for(int i=0;i
VIEWS ON THIS POST

75

Posted on:

Monday 22nd October 2012
View Replies!

GridBagLayout resizing is making component invisible

So I'm working on an app that has a JSplitPane. The right pane of the JSplitPane is a GridBagLayout ( I didn't choose it, the previous developers did). In it is a JTextField that is approx 10 characters wide. *Problem* If I make the GridBagLayout pane larger, everything works fine. But if I shrink it by setting the JSplitPane divider to halfway, the text field completely disappears, even though there is obviously more space to the right of it. I've set the JTextField's gridwidth to be the maximum possible, but it still disappears. Any suggestions\t
VIEWS ON THIS POST

111

Posted on:

Monday 22nd October 2012
View Replies!

JTable problem: not visible

i can't seem to get this example working. the code is as follows: import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Toolkit; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.JScrollPane; public class junk extends JFrame{ dbTableModel dbtm; public junk(){ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setPreferredSize(new Dimension(680, 330)); add(new myJPanel()); pack(); setVisible(true); } public class myJPanel extends JPanel{ Image image; public myJPanel(){ super(); setLayout(null); try { dbTableModel dbtm = new dbTableModel("com.mysql.jdbc.Driver","jdbc :-o dbc:nicholas","","","select * from spiderman"); } catch(Exception e){ e.printStackTrace(); } JButton x = new JButton("Climax"); x.setSize(new Dimension(100,50)); JTable b = new JTable(dbtm); b.setSize(new Dimension(300, 100)); b.setPreferredScrollableViewportSize(new Dimension(300,100)); JScrollPane p = new JScrollPane(b); p.setSize(new Dimension(300, 100)); add(p); add(x); b.setLocation(50,50); p.setLocation(50,50); x.setLocation(50,180); image=Toolkit.getDefaultToolkit().getImage("java_logo_full.png"); } public void paintComponent(Graphics g){ super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; //g2.scale(2.0, 2.0); g2.drawImage(image, 0, 0, this); } } public static void main(String[] args) { new junk(); } }
VIEWS ON THIS POST

85

Posted on:

Monday 22nd October 2012
View Replies!

Java Result: 1073807364- Printed as Output when setting internal frame visible

When i set a internal frame to visible i get Java Result: 1073807364 as the output. The systems hangs and will have to terminate the execution abruptly. What does this output stand for [ October 19, 2008: Message edited by: mohammed sanaullah ]
VIEWS ON THIS POST

72

Posted on:

Monday 22nd October 2012
View Replies!

scrolling JTable to make cells visible

Here is the code I am using to scroll JTable to its last cell and to make that cell visible. For some reason however, that cell is selected but the table does not scroll to it to make it visible. Can anyone help and tell me what I am doing wrong JTable table = codeEntryPN.getCodeDescriptionTable(); TableModelDataCapture tableModel = (TableModelDataCapture)table.getModel(); //adds a row of data to model to the end and fires row inserted tableModel.addDummyRow(); int lastRow = tableModel.getRowCount() - 1; table.setRowSelectionInterval(lastRow, lastRow); //makes the newly added row visible table.scrollRectToVisible(table.getCellRect(lastRow, 1, true));
VIEWS ON THIS POST

235

Posted on:

Tuesday 23rd October 2012
View Replies!