This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of DevSecOps Adventures: A Game-Changing Approach with Chocolate, LEGO, and Coaching Games and have Dana Pylayeva on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

JScrollPane

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i hv attached some fragments of my code below.
pl, tell y i am not able to get coloured scrollbars and also y whnevr i select any radiobutton(labeled as hidden 1, hiden2 etc)
the scrollpane size is same but scrollbar disaapers and all the radiobuttons get messed up and stuck yo each other making it difficult to make out wch radiobutton to select.
code is:

// Creating hidden layers label and combobox...
hiddenlyrlbl = new JLabel(" Hidden Layers ");
hiddenlyrlbl.setForeground(Color.black);
c2.gridx = 0;
c2.gridy = 2;
c2.gridwidth = 1;
c2.gridheight = 1;
gb2.setConstraints(hiddenlyrlbl, c2);
panel2.add(hiddenlyrlbl);

hiddenlyrcmb = new JComboBox();
hiddenlyrcmb.addItem("0");
for(int i = 1; i <= lv.arraylength; i++)
{
hiddenlyrcmb.addItem(String.valueOf(i));
}
hiddenlyrcmb.addItemListener(this);
hiddenlyrcmb.setEditable(true);
c2.gridx = 1;
c2.gridy = 2;
c2.gridwidth = 1;
c2.gridheight = 1;
gb2.setConstraints(hiddenlyrcmb, c2);
panel2.add(hiddenlyrcmb);
//Creating Hidden Layer Panel which has a label(nonelbl)...
hiddenlyrPnl = new JPanel();
hiddenlyrPnl.setLayout(new GridLayout(0, 1));
hiddenlyrPnl.setBorder(new TitledBorder("Hidden Layer"));

int ver = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int hor = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
jsp = new JScrollPane(hiddenlyrPnl, ver, hor);
jsp.doLayout();
jsp.setPreferredSize(new Dimension(140,130));
jsp.getHorizontalScrollBar().setBackground(Color.cyan);
jsp.getHorizontalScrollBar().setForeground(Color.red);
Color cll = jsp.getHorizontalScrollBar().getForeground();
jsp.getVerticalScrollBar().setBackground(Color.cyan);
jsp.setOpaque(true);
jsp.getVerticalScrollBar().setForeground(Color.red);
Color cl = jsp.getVerticalScrollBar().getForeground();
jsp.getVerticalScrollBar().setForeground(cl);
nonelbl = new JLabel("None");
hiddenlyrPnl.add(nonelbl);
c2.gridx = 0;
c2.gridy = 3;
c2.gridwidth = 2;
c2.gridheight =1;
gb2.setConstraints(jsp, c2);
panel2.add(jsp);
//-------------------------------------------------------------------------------------
// this code is inside actionPerformed()
if (hiddenchosen)
{
for(int i = 0 ; i < hiddenlyrbut.length; i++ )
{
try
{
if (e.getSource() == hiddenlyrbut[i])
{
lrnrulecmb.setEnabled(false);
String s = e.getActionCommand();
hbutindex = i;
createHiddenPanels(s);
Hnodestf.setText(String.valueOf(currHnodes[i]));
Hbiascmb.setSelectedItem(String.valueOf(currHbias[i]));
Hlrnratecmb.setSelectedItem(String.valueOf(currHLrate[i]));
Hactvcmb.setSelectedItem(currHactvselection[i]);
//hiddenchosen = false;
paramPnl = new JPanel();
gb4 = new GridBagLayout();
c4 = new GridBagConstraints();
paramPnl.setLayout(gb4);
c4.fill = GridBagConstraints.BOTH;
c4.anchor = GridBagConstraints.NORTH;
gb4.setConstraints(paramPnl, c4);

paramPnl.add(hiddenDefPanel);
switchParamPanel(paramPnl);
}
}
//-------------------------------------------------------------------------------------
// Creates hidden radio buttons and adding it to hiddenlyrPnl...
void createhiddenlyrPnl(int n)
{
hiddenlyrbut = new JRadioButton[n];
currHactvselection = new String[n];//variable array to store current Hactvcmb choice
currHnodes = new int[n];//denotes no.of neurons in each hidden layer.
currHbias = new double[n];//denotes bias in each hidden layer.
currHLrate = new double[n];//denotes learning rate for each hidden layer.

hiddenlyrPnl.removeAll();

hiddenlyrPnl.setLayout(new GridLayout(n, 1));
if (n == 0)
{
nonelbl = new JLabel("None");
hiddenlyrPnl.add(nonelbl);
}
else
{
if(n<0)
return;
else
{
for(int i = 0; i < n; i++)
{
currHnodes[i] = lv.hnodes[i] = 3;
currHbias[i] = lv.Hbias[i] = -1.0d;
currHLrate[i] = lv.HLrate[i] = 0.7d;
currHactvselection[i] = "Unipolar Sigmoidal";
hiddenlyrbut[i] = new JRadioButton("Hidden Layer" + " " + (i+1));
hiddenlyrPnl.add(hiddenlyrbut[i]);
hiddenlyrbut[i].addActionListener(this);
bg1.add(hiddenlyrbut[i]);
}
}
}
cp.invalidate();
cp.doLayout();
cp.validate();
cp.repaint();
}
//------------------------------------------------------------------------------------
void createHiddenPanels(String s)
{
//create o/p def panel
hiddenDefPanel = new JPanel();
hiddenDefPanel.setBorder(new TitledBorder(s + " Definition"));
gb7 = new GridBagLayout();
c7 = new GridBagConstraints();
hiddenDefPanel.setLayout(gb7);
c7.fill = GridBagConstraints.HORIZONTAL;

nodeslabel = new JLabel(" Nodes ");
nodeslabel.setForeground(Color.black);
c7.gridx = 0;
c7.gridy = 0;
c7.gridwidth = 1;
c7.gridheight = 1;
gb7.setConstraints(nodeslabel, c7);
hiddenDefPanel.add(nodeslabel);

Hnodestf = new JTextField(6);
Hnodestf.setText(" 5 ");
Hnodestf.setEditable(true);
Hnodestf.addActionListener(this);
c7.gridx = 1;
c7.gridy = 0;
c7.gridwidth = 1;
c7.gridheight = 1;
c7.insets = new Insets(0, 20, 5, 150);
gb7.setConstraints(Hnodestf, c7);
hiddenDefPanel.add(Hnodestf);

biaslbl = new JLabel(" Bias ");
biaslbl.setForeground(Color.black);
c7.gridx = 0;
c7.gridy = 1;
c7.gridwidth = 1;
c7.gridheight = 1;
c7.insets = new Insets(0, 0, 0, 0);
gb7.setConstraints(biaslbl, c7);
hiddenDefPanel.add(biaslbl);
Hbiascmb = new JComboBox();
Hbiascmb.addItem("-1");
Hbiascmb.addItem("0");
Hbiascmb.addItem("1");
Hbiascmb.setEditable(true);
Hbiascmb.addItemListener(this);
c7.gridx = 1;
c7.gridy = 1;
c7.gridwidth = 1;
c7.gridheight = 1;
c7.insets = new Insets(0, 20, 5, 150);
gb7.setConstraints(Hbiascmb, c7);
Hbiascmb.setOpaque(true);
Hbiascmb.setBackground(Color.white);
Hbiascmb.setForeground(Color.blue);
hiddenDefPanel.add(Hbiascmb);
lrnratelbl = new JLabel(" Learning rate ");
lrnratelbl.setForeground(Color.black);
c7.gridx = 0;
c7.gridy = 2;
c7.gridwidth = 1;
c7.gridheight = 1;
c7.insets = new Insets(0, 0, 0, 0);
gb7.setConstraints(lrnratelbl, c7);
hiddenDefPanel.add(lrnratelbl);

Hlrnratecmb = new JComboBox();
Hlrnratecmb.addItem("0.7");
Hlrnratecmb.addItem("0.8");
Hlrnratecmb.setEditable(true);
Hlrnratecmb.addItemListener(this);
c7.gridx = 1;
c7.gridy = 2;
c7.gridwidth = 1;
c7.gridheight = 1;
c7.insets = new Insets(0, 20, 5, 150);
gb7.setConstraints(Hlrnratecmb, c7);
hiddenDefPanel.add(Hlrnratecmb);

//actvfuncPnl contains label, combobox, and advance JButton.
actvPnl = new JPanel();
actvPnl.setBorder(new TitledBorder("Activation Setting"));
c7.gridx = 0;
c7.gridy = 3;
c7.gridwidth = 2;
c7.gridheight = 2;
c7.fill = GridBagConstraints.HORIZONTAL;
c7.insets = new Insets(0, 0, 0, 0);
gb13 = new GridBagLayout();
c13 = new GridBagConstraints();
actvPnl.setLayout(gb13);
c13.fill = GridBagConstraints.BOTH;
gb7.setConstraints(actvPnl, c7);
hiddenDefPanel.add(actvPnl, c7);

actvlabel = new JLabel("Activation Function");
actvlabel.setForeground(Color.black);
c13.gridx = 0;
c13.gridy = 0;
c13.gridwidth = 1;
c13.gridheight = 1;
gb13.setConstraints(actvlabel, c13);
actvPnl.add(actvlabel);

Hactvcmb = new JComboBox();
Hactvcmb.addItem(" Unipolar Sigmoid");
Hactvcmb.addItem(" Bipolar Sigmoid");
Hactvcmb.addItem(" Tan Hyperbolic");
Hactvcmb.addItem(" Unipolar Sine");
Hactvcmb.addItem(" Bipolar Sine");
Hactvcmb.addItem(" Unipolar Cosine");
Hactvcmb.addItem(" Bipolar Cosine");
Hactvcmb.addItem(" Decaying Exponential");
Hactvcmb.addItem(" Unipolar ArcTangent");
Hactvcmb.addItem(" Bipolar ArcTangent");
Hactvcmb.addItem(" Gaussian1");
Hactvcmb.addItem(" Gaussian2");
Hactvcmb.addItem(" net to the power'n'");
Hactvcmb.addItem(" Min function");
Hactvcmb.addItem(" Max function");
Hactvcmb.addItem(" Slow Sigmoid");
Hactvcmb.addItem(" Non-saturating Activation Function");
Hactvcmb.addItem(" Bipolar Logarithmic");
Hactvcmb.addItem(" Min-Max function");
Hactvcmb.addItem(" Unipolar Threshold");
Hactvcmb.addItem(" Bipolar Threshold");
Hactvcmb.addItem(" Signum function");
Hactvcmb.addItem(" Linear function");
Hactvcmb.addItem(" Unipolar Threshold Piecewise Linear");
Hactvcmb.addItem(" Bipolar Threshold Piecewise Linear");
Hactvcmb.addItem(" Cauchy Transfer function");
Hactvcmb.addItemListener(this);
Hactvcmb.addActionListener(this);
c13.gridx = 1;
c13.gridy = 0;
c13.gridwidth = 2;
c13.gridheight = 1;
gb13.setConstraints(Hactvcmb, c13);
actvPnl.add(Hactvcmb);

Hactvadvbut = new JButton("Advance...");
Hactvadvbut.setOpaque(true);
Hactvadvbut.setBackground(Color.darkGray);
Hactvadvbut.setForeground(Color.white);
Hactvadvbut.setBorder(new BevelBorder(BevelBorder.RAISED));
Hactvadvbut.addActionListener(this);
c13.gridx = 1;
c13.gridy = 1;
c13.gridwidth = 1;
c13.gridheight = 1;
gb13.setConstraints(Hactvadvbut, c13);
actvPnl.add(Hactvadvbut);
}
//------------------------------------------------------------------------------------------
//in itemS choosing total no.of hiddenlayers to be constructed------------------------------
if (ie.getSource() == hiddenlyrcmb)
{
try
{
hiddenchosen = true;
String str = (String) ie.getItem();
int numh = Integer.parseInt(str);
lv.numhiddenlayers = Integer.parseInt(str);
lv.hnodes = new int[lv.numhiddenlayers];
lv.Hbias = new double[lv.numhiddenlayers];
lv.HLrate = new double[lv.numhiddenlayers];
lv.hiddenlyrInfo = new double[lv.numhiddenlayers][4];

createhiddenlyrPnl(numh);
}
//-----------------------------------------------------------------------------------
thanx
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Remi / Vandana
I took a look at your code fragments, but it is a little unclear. I would just point out a few gui design tips and hopefully these should solve your problem:
1. if your main panel has a border layout, the preferrd size of any component might not be set/taken into consideration. for eg. if you add a jscrollpane in the "Center" of panel2, the jsp will fill the center, whatever be the preffered size.
2. in gridbag layout do not leave any of the cell/space balank. if you require a blank space, insert a blank label. In case you leave any space blank it will give a totally differnt output. Also, sometimes you need to set the "fill" of the gbc to get a proper output.
3. it seems that you want to display a set of components depending upon a radiobutton selection. itf it involves different components to be displayed, using a card layout is a good idea. you can define your layouts on different cards and as per the selection show a particular card.
Good luck...
Amit
 
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic