Split Pane & JTable - program hangs. Help!


I have a split pane with the top half used for ComboBoxes and search criteria and the bottom half devoted to displaying the results of the search criteria in a JTable.

This is how I bind my panels:

doublePane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, comboPanel, jsp);
doublePane.setOneTouchExpandable(true);
doublePane.setDividerLocation(200);

(jsp is the JScrollPane in which I have my JTable).

And this is how I try to display them:

getContentPane().add(doublePane);

setVisible(true);

And yet when I run it the program just hangs. Any Ideas
Posted On: Tuesday 23rd of October 2012 10:55:16 PM Total Views:  72
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




create a jtable which can combine and split and the image change also

hi newbie here and would like to know how to create a jtable with default images and with specific column and rows that if you combine the cells the image enlarge and when split the image decreases.
VIEWS ON THIS POST

205

Posted on:

Wednesday 19th September 2012
View Replies!

Tree and drawing within the same panel

I want to place both the tree and my drawing with in the same panel..I used borderlayout..But its getting overlap..How can i do it..Help me..
VIEWS ON THIS POST

38

Posted on:

Monday 22nd October 2012
View Replies!

Displaying certain items on a panel based on radio button selection.

Hi , I have to design a GUI where in user should enter information like name, ID number, university, company etc. I have to provide radio button selection to choose between two sets of information. For example, let radioButton1(student) be the default where in the panel should display name, ID number and University. If radioButton2(employee) is selected, the panel should now display name, ID number and company(i.e should not display University field). It would have been easier if I could just disable the unwanted components based on selection but am not sure how to display only selected items. I have pasted my code which renders the panel properly initially and disables the unwanted items. Please tell me how I could change the code to display only selcted items.
VIEWS ON THIS POST

68

Posted on:

Monday 22nd October 2012
View Replies!

MouseEvent in JScrollpane

I'm using a JScrollPane that contains a number of JPanels. These JPanels are selectable, and if one is double clicked on a MouseEvent is generated and is handled by the following method: public void handleMouseEvent(MouseEvent me) { Point p = SwingUtilities.convertPoint(me.getComponent(), me.getPoint(), this.scrollPane); Component c = scrollPane.getViewport().getComponent(0). getComponentAt(p.x, p.y); if (c != null && c instanceof SpecialPanel) { this.unselectSpecialPanels(); this.recolorBackgrounds(); ((SpecialPanel) c).setSelected(true); } }
VIEWS ON THIS POST

40

Posted on:

Monday 22nd October 2012
View Replies!

Can any one send demo program for tabbed pane in Swing

I want to keep four types of information(Basic,Preference,history,partner etc.) in one window using tab.If you have any demo code please help me.
VIEWS ON THIS POST

37

Posted on:

Monday 22nd October 2012
View Replies!

Adding a 'left pane' Menu to an MDI

I want to add a left pane to an MDI. Much like the ones that appear in IDEs. But I can't find any information on how to do it. Can anyone please help Here is a picture of something similar to what I want to do: http://www.javio.com/compsuite/big_outlookbar.jpg [ March 11, 2007: Message edited by: Roberto Guerra ]
VIEWS ON THIS POST

16

Posted on:

Monday 22nd October 2012
View Replies!

Jlabel pushing graphics panel out of view

Hi can anybody help with this java swing problem. Here is the code... import javax.swing.*; import java.awt.*; import java.awt.geom.*; public class MyApplet extends JApplet { public void init() { Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(new ButtonPanel(), BorderLayout.WEST); content.add(new LabelPanel(), BorderLayout.CENTER); content.add(new GridPanel(), BorderLayout.EAST); } class ButtonPanel extends JPanel { ButtonPanel() { this.add(new JButton("Press")); } } class LabelPanel extends JPanel { LabelPanel() { this.add(new JLabel(" World")); } } class GridPanel extends JPanel { public void paint (Graphics g) { Graphics2D g2D = (Graphics2D)g; g2D.setColor(Color.WHITE); for(int i = 0; i < 450; i += 10) g2D.draw(new Line2D.Float(i, 0, i, 450)); for(int i = 0; i < 450; i += 10) g2D.draw(new Line2D.Float(0, i, 450, i)); } } } What I expected to see was a JButton on the left of the applet, a label saying " World" and then a cross-hatched grid on the right of the applet measuring 450 x 450 pixels. Instead it appears that the " World" label has expanded across the applet display area and pushed the grid to the extreme right. Has anybody got any idea how I can stop the JLabel from pushing my grid off the applet.
VIEWS ON THIS POST

30

Posted on:

Monday 22nd October 2012
View Replies!

The control panel strip of MediaPlayer is blank when content is playing

Knute Johnson in comp.lang.java.programmer told me to update JDK to 1.6.0beta2 and I found this problem disappear in 1.6.0beta2. http://groups.google.com/group/comp.lang.java.programmer/browse_thread/thread/670b99b9770c214a/e5d2a1443f48bed7lnk=gst&q=jmf&rnum=1#e5d2a1443f48bed7
VIEWS ON THIS POST

30

Posted on:

Monday 22nd October 2012
View Replies!

How can I split JButton? Any idea?

I just need a regular JButton that will differently respond if a user click at left or right half of the JButton. It will serve as "Back/Forward" buttons, but mixed into single JButton. Any idea on how to implement such functionality
VIEWS ON THIS POST

68

Posted on:

Monday 22nd October 2012
View Replies!

jsplitpane resizing problem

hi, i have a jsplitpane that has a jscrollpane on the left on the right.The one on the left contans a jtree while the one on the right contains several jpanel(and different layout managers).The problem comes in the displayam of the split pane, its compressed and i have to manually resize it to see the components. i thot that on calling the frame's pack(), the frame is resized according to the components it contained but apparently this isn't the case.Further more, i displayed the components' sizes and they're all Dimension(0,0). Seems i forgot something , or should i expicitly set some minimum size to all jpanels .. am really not sure of what to do , so if anyone could give me an idea , i'd be super grateful.
VIEWS ON THIS POST

81

Posted on:

Tuesday 23rd October 2012
View Replies!

Loading and unloading panels on one side of JSplitPane

Hi all I'm trying to create an application where on one side of a JSplitPane is the navigation and on the other side panels are loaded. For example, on the left side, when i click Add Item, on the right side the panel that is for adding an item is displayed. If I click Options on the left side, the Add Item panel is unloaded from memory and the Options panel is loaded. I dont want to use CardLayout because I may have to use as many as 50 panels. Each panel is a different class. The navigation is also also on a panel that is on the left side of the JSplitPane. On the right side also there is a panel which loads other external panels into it. So how do I give command to the right side panel to load a specific panel Any links to example applications with source also really appreciated.
VIEWS ON THIS POST

36

Posted on:

Tuesday 23rd October 2012
View Replies!

removing and adding a panel inside actionPerformed ??

hi , thanks for your attention btw so i've come to something weird that made me think that no changes to a JPanel can be done inside the actionPerformed method so here is how it started Say that you want to change the whole content of a panel (i think...) the easiest thing to do is just probably create another panel then you do whatever you do inside that new panel, when you want to change it, just remove that newly created panel then create and add another one so i made a button that when clicked remove a panel, then add another one to the main container (the one i got from getContentPane()), but it didn't work, so then i tried adding pane.validate() and pane.repaint() (pane is the main container) and they didn't work either and then i checked both my textbooks and found that they don't have in depth discussion on these things so i would really appreciate if someone points me the direction to a tutorial on this or explain it to me directly thx
VIEWS ON THIS POST

57

Posted on:

Tuesday 23rd October 2012
View Replies!

Posting it again (Urgent!) Can't display chinese and japanese font at the same time

The following program tries to display a string that contains mostly japanese characters along with few chinese characters. When I try "java I18NTest zh ZH" it shows all japanese and chinese characters properly except one. When I try "java I18NTest ja JA" its shows the japanese fine but messes up the chinese characters. What do I have to do so that it displays all japanese and chinese characters properly Following is the java code and the .properties files (both the properties files are same though). I'm sure that the problem has nothing to do with system fonts as there is a third party java application that shows those characters properly on my machine. Any help will really be appreciated.
VIEWS ON THIS POST

98

Posted on:

Tuesday 23rd October 2012
View Replies!

Can't display chinese and japanese at the same time (Urgent!!!!)

Ok, the following program tries to display a string that contains mostly japanese characters along with few chinese characters. When I try "java I18NTest zh ZH" it shows all japanese and chinese characters properly except one. When I try "java I18NTest ja JA" its shows the japanese fine but messes up the chinese characters. What do I have to do so that it displays all japanese and chinese characters properly Following is the java code and the .properties files (both the properties files are same though). I'm sure that the problem has nothing to do with system fonts as there is a third party java application that shows those characters properly on my machine. Any help will really be appreciated.
VIEWS ON THIS POST

74

Posted on:

Tuesday 23rd October 2012
View Replies!

controlling size of part of split pane and another error

I am new to Swing. I've got two problems in the code below javascript: x() banghead 1)for some reason, the whiteboard is showing up as just a tiny sliver on the left hand side. 2)when I expand the whiteboard panel and start drawing on it, the label and the border for that component get duplicated. This code should be ready to run (MainPanel is the executable). The only prerequisite is to have some hello.gif in the same folder. import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.DefaultListModel; import javax.swing.JCheckBox; import javax.swing.JColorChooser; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JMenuBar; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.JTree; import javax.swing.ListSelectionModel; import javax.swing.table.DefaultTableModel; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeSelectionModel; public class MainPanel extends JPanel implements ActionListener { static JFrame frame; JTextArea textArea; JTextField textField; JList list; JTable table; JTree tree; JColorChooser colorChooser; JCheckBox toggleDnD; WebToolBar webToolBar; private WebBrowserPane browserPane; private SimpleWhiteboard whiteBoard; public MainPanel() { super(new BorderLayout()); JPanel rightPanel = createVerticalBoxPanel(); JPanel leftPanel = createVerticalBoxPanel(); JPanel topPanel = createTopPanel(); // top browserPane = new WebBrowserPane(); webToolBar = new WebToolBar(browserPane); topPanel.add(createPanelForComponent(webToolBar, "WebToolBar")); // RIGHT COLUMN // Create a color chooser. colorChooser = new JColorChooser(); rightPanel.add(createPanelForComponent(colorChooser, "JColorChooser")); // LEFT COLUMN // Create a textfield. whiteBoard = new SimpleWhiteboard(); leftPanel.add(createPanelForComponent(whiteBoard, "SimpleWhiteboard")); // Create the toggle button. toggleDnD = new JCheckBox("Turn on Drag and Drop"); toggleDnD.setActionCommand("toggleDnD"); toggleDnD.addActionListener(this); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel); splitPane.setOneTouchExpandable(true); add(topPanel, BorderLayout.NORTH); add(splitPane, BorderLayout.CENTER); add(toggleDnD, BorderLayout.PAGE_END); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); } protected JPanel createVerticalBoxPanel() { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS)); p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); return p; } protected JPanel createTopPanel() { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS)); p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); return p; } public JPanel createPanelForComponent(JComponent comp, String title) { JPanel panel = new JPanel(new BorderLayout()); panel.add(comp, BorderLayout.CENTER); if (title != null) { panel.setBorder(BorderFactory.createTitledBorder(title)); } return panel; } public void actionPerformed(ActionEvent e) { if ("toggleDnD".equals(e.getActionCommand())) { boolean toggle = toggleDnD.isSelected(); textArea.setDragEnabled(toggle); textField.setDragEnabled(toggle); list.setDragEnabled(toggle); table.setDragEnabled(toggle); tree.setDragEnabled(toggle); colorChooser.setDragEnabled(toggle); } } /** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. */ private static void createAndShowGUI() { // Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); // Create and set up the window. frame = new JFrame("BasicDnD"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create and set up the content pane. JComponent newContentPane = new MainPanel(); newContentPane.setOpaque(true); // content panes must be opaque frame.setContentPane(newContentPane); // Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { // Schedule a job for the event-dispatching thread: // creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } } ------------------------------------- import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SimpleWhiteboard extends JPanel { private Point oldPoint, newPoint; protected ImageIcon image; private boolean start = true; // set up GUI and register mouse event handler public SimpleWhiteboard() { // super( "A simple whiteboard program" ); setBackground( Color.WHITE ); image = new ImageIcon( getClass().getResource( "hello.gif" ) ); addMouseMotionListener( new MouseMotionAdapter() { // anonymous inner class // store drag coordinates and repaint public void mouseDragged( MouseEvent event ) { if ( start ) { newPoint = event.getPoint(); start = false; } else { oldPoint = newPoint; newPoint = event.getPoint(); repaint(); } } public void mouseMoved( MouseEvent event ) { start = true; } } // end anonymous inner class ); // end call to addMouseMotionListener setSize( 1200, 700 ); setVisible( true ); } // end Painter constructor // draw oval in a 4-by-4 bounding box at specified location on window public void paint( Graphics g ) { if ( start ) { image.paintIcon( this, g, 0, 0 ); } else g.drawLine( oldPoint.x, oldPoint.y, newPoint.x, newPoint.y ); } public static void main( String args[] ) { SimpleWhiteboard application = new SimpleWhiteboard(); // application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } } // end class Painter ------------------------------------ // WebBrowserPane.java // WebBrowserPane is a simple Web-browsing component that // extends JEditorPane and maintains a history of visited URLs. // Java core packages import java.util.*; import java.net.*; import java.io.*; // Java extension packages import javax.swing.*; import javax.swing.event.*; public class WebBrowserPane extends JEditorPane { private List history = new ArrayList(); private int historyIndex; // WebBrowserPane constructor public WebBrowserPane() { // disable editing to enable hyperlinks setEditable( false ); } // display given URL and add it to history public void goToURL( URL url ) { displayPage( url ); history.add( url ); historyIndex = history.size() - 1; } // display next history URL in editorPane public URL forward() { historyIndex++; // do not go past end of history if ( historyIndex >= history.size() ) historyIndex = history.size() - 1; URL url = ( URL ) history.get( historyIndex ); displayPage( url ); return url; } // display previous history URL in editorPane public URL back() { historyIndex--; // do not go past beginning of history if ( historyIndex < 0 ) historyIndex = 0; // display previous URL URL url = ( URL ) history.get( historyIndex ); displayPage( url ); return url; } // display given URL in JEditorPane private void displayPage( URL pageURL ) { // display URL try { setPage( pageURL ); } // handle exception reading from URL catch ( IOException ioException ) { ioException.printStackTrace(); } } } ----------------------------- // WebToolBar.java // WebToolBar is a JToolBar subclass that contains components // for navigating a WebBrowserPane. WebToolBar includes back // and forward buttons and a text field for entering URLs. // Java core packages import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.MalformedURLException; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JTextField; import javax.swing.JToolBar; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; public class WebToolBar extends JToolBar implements HyperlinkListener { private WebBrowserPane webBrowserPane; private JButton backButton; private JButton forwardButton; private JTextField urlTextField; // WebToolBar constructor public WebToolBar( WebBrowserPane browser ) { super( "Web Navigation" ); // register for HyperlinkEvents webBrowserPane = browser; webBrowserPane.addHyperlinkListener( this ); // create JTextField for entering URLs urlTextField = new JTextField( 25 ); urlTextField.addActionListener( new ActionListener() { // navigate webBrowser to user-entered URL public void actionPerformed( ActionEvent event ) { // attempt to load URL in webBrowserPane try { URL url = new URL( urlTextField.getText() ); webBrowserPane.goToURL( url ); } // handle invalid URL catch ( MalformedURLException urlException ) { urlException.printStackTrace(); } } } ); // create JButton for navigating to previous history URL backButton = new JButton( new ImageIcon( getClass().getResource( "images/back.gif" ) ) ); backButton.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent event ) { // navigate to previous URL URL url = webBrowserPane.back(); // display URL in urlTextField urlTextField.setText( url.toString() ); } } ); // create JButton for navigating to next history URL forwardButton = new JButton( new ImageIcon( getClass().getResource( "images/forward.gif" ) ) ); forwardButton.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent event ) { // navigate to next URL URL url = webBrowserPane.forward(); // display new URL in urlTextField urlTextField.setText( url.toString() ); } } ); // add JButtons and JTextField to WebToolBar add( backButton ); add( forwardButton ); add( urlTextField ); } // end WebToolBar constructor // listen for HyperlinkEvents in WebBrowserPane public void hyperlinkUpdate( HyperlinkEvent event ) { // if hyperlink was activated, go to hyperlink's URL if ( event.getEventType() == HyperlinkEvent.EventType.ACTIVATED ) { // get URL from HyperlinkEvent URL url = event.getURL(); // navigate to URL and display URL in urlTextField webBrowserPane.goToURL( url ); urlTextField.setText( url.toString() ); } } }
VIEWS ON THIS POST

62

Posted on:

Tuesday 23rd October 2012
View Replies!

how to detect click on panel

Hi everybody, This is a hopelessly newbie question. I need to detect mouse clicks on a panel, and I'm not sure which Listener interface to use. I tried to use MouseListener but I got the 'symbol not recognized' message when I tried to compile: MyPanel myPanel = new MyPanel(); silPanel.addActionListener(new MyMouseListener());
VIEWS ON THIS POST

17

Posted on:

Tuesday 23rd October 2012
View Replies!

Freeze a panel on top of desktop

Iam not that used to SWINGS. I need to place a panel on the desktop of height say 3cm on top of the desktop. I can do this easily but my case is different. My case is after placing the panel on top of the desktop whatever window i open should be automatically resized in such a way that my panel is always visible. Or rather in simple words, the top 3cm of my desktop should be reserved for my panel and at any cost it shouldnt be overlapped.
VIEWS ON THIS POST

21

Posted on:

Tuesday 23rd October 2012
View Replies!

JFrame panels NOT showing. WHY??

I am fairly new to Java. I cannot work out why Im getting a JFrame but none of the panels I created are showing. Can anyone help me out This is what I have............ public class statecap extends JFrame implements ActionListener { JTextField display = new JTextField(8); JButton exit = new JButton("Exit"); JButton check = new JButton("Check Answer"); public statecap() { super ("States & Capitals"); JFrame frame = new JFrame(); setSize(430,430); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //create first panel JPanel pstates = new JPanel(); pstates.setLayout(new BoxLayout(pstates, BoxLayout.Y_AXIS)); JRadioButton cal = new JRadioButton("California"); cal.setMnemonic(KeyEvent.VK_1); cal.setActionCommand("California, Sacremento"); cal.setSelected(true); JRadioButton col = new JRadioButton("Colorado"); col.setMnemonic(KeyEvent.VK_2); col.setActionCommand("Colorado, Denver"); JRadioButton ill = new JRadioButton("Illinois"); ill.setMnemonic(KeyEvent.VK_3); ill.setActionCommand("Illinois, "); JRadioButton ore = new JRadioButton("Oregon"); ore.setMnemonic(KeyEvent.VK_4); ore.setActionCommand("Oregon, Salem"); JRadioButton wis = new JRadioButton("Wisconsin"); wis.setMnemonic(KeyEvent.VK_5); wis.setActionCommand("Wisconsin"); pstates.setVisible(true); //Group the radio buttons. ButtonGroup cgroup = new ButtonGroup(); cgroup.add(cal); cgroup.add(col); cgroup.add(ill); cgroup.add(ore); cgroup.add(wis); //Register a listener for the radio buttons. cal.addActionListener(this); col.addActionListener(this); ill.addActionListener(this); ore.addActionListener(this); wis.addActionListener(this); //create second panel JPanel pcapitals = new JPanel(); pcapitals.setLayout(new BoxLayout(pcapitals, BoxLayout.Y_AXIS)); JRadioButton den = new JRadioButton("Denver", true); den.setMnemonic(KeyEvent.VK_1); den.setSelected(true); JRadioButton mad = new JRadioButton("Madison"); den.setMnemonic(KeyEvent.VK_2); JRadioButton sac = new JRadioButton("Sacramento"); den.setMnemonic(KeyEvent.VK_3); JRadioButton sal = new JRadioButton("Salem"); den.setMnemonic(KeyEvent.VK_4); JRadioButton spr = new JRadioButton("Springfield"); den.setMnemonic(KeyEvent.VK_5); pcapitals.setVisible(true); //button group creation ButtonGroup sgroup = new ButtonGroup(); sgroup.add(den); sgroup.add(mad); sgroup.add(sac); sgroup.add(sal); sgroup.add(spr); //create third panel JPanel finalpanel = new JPanel(); finalpanel.setLayout(new BoxLayout(finalpanel, BoxLayout.Y_AXIS)); //create and add the items check.addActionListener(this); exit.addActionListener(this); finalpanel.add(display); finalpanel.add(check); finalpanel.add(exit); finalpanel.setVisible(true); //put panels together Container contentPane = getContentPane(); contentPane.add(pstates, BorderLayout.WEST); contentPane.add(pcapitals, BorderLayout.CENTER); contentPane.add(pcapitals, BorderLayout.EAST); setVisible(true); frame.show(); } //event handler public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == check) { display.setText(e.getActionCommand()); } if (source == exit) { System.exit(0); } } public static void main(String[] args) { statecap test = new statecap(); test.setVisible(true); } }
VIEWS ON THIS POST

31

Posted on:

Tuesday 23rd October 2012
View Replies!