Hello,
I am a beginner programmer and have Eclipse Java EE IDE for Web Developers (Version: Juno Release), I have a Windows 7 Home Premium PC.
My question is in Java using Eclipse, how would I change the color of a panel or button of a GUI window? How can I add a tabbed pane to the program I have? Would I need to create a new class for each? Would I need to create a new program and link it? Would I need to create a new class and then package it somehow? Or would I add to the existing program I want to add to and insert the code there?
I have this link:
http://docs.oracle.com/javase/tutori...abbedpane.html but I don't know how I would add this to my current existing program?
In the current code I have - the GUI frame is already coded and set to visible (shown below) so to change the panel color - would I just add "mainFrame.setColor(blue);"
Here's what's already there:
mainFrame.setSize(260, 150);
mainFrame.setVisible(true);
Also to add a tab - would I need to just add the following to the current program:
JTabbedPane tabbedPane = new JTabbedPane();
ImageIcon icon = createImageIcon("images/middle.gif");
JComponent panel1 = makeTextPanel("Panel #1");
tabbedPane.addTab("Tab 1", icon, panel1, "Does nothing");
tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
JComponent panel2 = makeTextPanel("Panel #2");
tabbedPane.addTab("Tab 2", icon, panel2, "Does twice as much nothing");
tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
//Add the tabbed pane to this panel.
add(tabbedPane);
//The following line enables to use scrolling tabs.
tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); }
protected JComponent makeTextPanel(String text) {
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler); return panel; }
/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = TabbedPaneDemo.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null; } }
Thank you in advance for any help - much appreciated!