Results 1 to 2 of 2
  1. #1
    puan12 is offline Member
    Join Date
    Jul 2014
    Posts
    7
    Rep Power
    0

    Default How to create an outline for table row in Java in Nimbus LaF

    I have a simple table. I am using Nimbus LaF. I have changed some key values to get the dark theme.
    Normally In nimbus LaF, It will focus only the selected cell.
    I would like to get Focus(border) for whole selected row.
    Could someone tell me how can i achieve this?

    Here is my code

    Java Code:
    public class SimpleTableDemo extends JPanel
    {
    
    	private boolean DEBUG = false;
    	 
        public SimpleTableDemo() {
            super(new GridLayout(1,0));
     
            String[] columnNames = {"First Name",
                                    "Last Name",
                                    "Sport",
                                    "# of Years",
                                    "Vegetarian"};
     
            Object[][] data = {
            {"Kathy", "Smith",
             "Snowboarding", new Integer(5), new Boolean(false)},
            {"John", "Doe",
             "Rowing", new Integer(3), new Boolean(true)},
            {"Sue", "Black",
             "Knitting", new Integer(2), new Boolean(false)},
            {"Jane", "White",
             "Speed reading", new Integer(20), new Boolean(true)},
            {"Joe", "Brown",
             "Pool", new Integer(10), new Boolean(false)}
            };
     
            final JTable table = new JTable(data, columnNames);
            table.setPreferredScrollableViewportSize(new Dimension(500, 70));
            table.setFillsViewportHeight(true);
     
            if (DEBUG) {
                table.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e) {
                        printDebugData(table);
                    }
                });
            }
     
            //Create the scroll pane and add the table to it.
            JScrollPane scrollPane = new JScrollPane(table);
     
            //Add the scroll pane to this panel.
            add(scrollPane);
        }
     
        private void printDebugData(JTable table) {
            int numRows = table.getRowCount();
            int numCols = table.getColumnCount();
            javax.swing.table.TableModel model = table.getModel();
     
            System.out.println("Value of data: ");
            for (int i=0; i < numRows; i++) {
                System.out.print("    row " + i + ":");
                for (int j=0; j < numCols; j++) {
                    System.out.print("  " + model.getValueAt(i, j));
                }
                System.out.println();
            }
            System.out.println("--------------------------");
        }
     
        /**
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
         */
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("SimpleTableDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
            //Create and set up the content pane.
            SimpleTableDemo newContentPane = new SimpleTableDemo();
            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) {
        	
        	UIManager.put("control", new Color(65,65,65));
        	UIManager.put("nimbusSelectionBackground", new Color(34,129,184));
        	UIManager.put("nimbusBase", new Color(65,65,65));
        	UIManager.put("text", new Color(255,255,255));
         	
        	try {for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        	}
    	    	
     catch (ClassNotFoundException e) {}
            catch (InstantiationException e) {}
            catch (IllegalAccessException e) {}
            catch (UnsupportedLookAndFeelException e)  {}
        	
       javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    }
    Thanks in advance

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,143
    Rep Power
    14

    Default Re: How to create an outline for table row in Java in Nimbus LaF

    Use a custom table renderer. Recommended reading: How to Use Tables (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

    Try that out, and if you can't get it working, post an MCVE. Note that the code you posted contains a bunch of extraneous methods that don't have anything to do with your problem, so you should get rid of them.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

Similar Threads

  1. Replies: 3
    Last Post: 06-17-2013, 03:28 PM
  2. Replies: 1
    Last Post: 04-23-2013, 05:25 PM
  3. table renderer problem in nimbus look and feel
    By Allgorythm in forum New To Java
    Replies: 0
    Last Post: 02-22-2010, 12:20 PM
  4. Replies: 2
    Last Post: 09-14-2009, 10:25 PM
  5. Replies: 0
    Last Post: 08-15-2009, 08:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •