There is a Tabs component which has two tab :
private Tabs tabClient = new Tabs();
...
tabClient.addTab("Fiche", cFicheClient); // cFicheClient is a Container
tabClient.addTab("Crédits", cClientEtCredits); // cClientEtCredits is a Container
tabClient.addTabsFocusListener(this);
public void focusGained(Component arg0) {
String noms = Formatage.getColumnValueAt(String.valueOf(fichesignalitique.elementAt(0)).toUpperCase(), 11);
if (tabClient.getSelectedIndex() == 0)
{
setTitle("Fiche signalétique de " + noms);
photosBtn.requestFocus();
}
else
{
setTitle("Liste des crédits de " + noms);
recapClient.requestFocus();
}
repaint();
}
In runtime I cannot click the "Crédits" tab : the Tabs doesn't show the components of the cClientEtCredits Container ! And also the Form's title is not displayed when the Form is shown but I must click one tab button in order to show the Form's title !
So why ?
I'm guessing its because of the request focus call within a focus listener.
You should probably change the tab selection before moving the focus to a different component by using something like setSelectedIndex.
Related
I'm using barteksc pdf viewer library to load pdf in my application.
pdfView = findViewById(R.id.pdfView);
pdfView.fromAsset(getResources().getString(R.string.pdfname))
.enableDoubletap(true)
.enableSwipe(true)
.defaultPage(pageNumber)
.onPageChange(mainreading.this)
.pageFitPolicy(FitPolicy.WIDTH)
.pageFling(true)
.linkHandler(null)
.enableAnnotationRendering(true)
.swipeHorizontal(true)
.scrollHandle(new DefaultScrollHandlenew(mainreading.this))
.enableAntialiasing(true)
.load();
}
I want pdf to start scroll automatically when user click the button of volume up and down buttons to start stop. I tried with below code while wrapping it in the handler with handler.performClick(); but it shows blank screen while scrolling up and down.
scrollbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
pdfView.scrollTo(0, pdfView.getScrollY() + 24);
}
});
Example :
https://play.google.com/store/apps/details?id=com.emptysheet.pdfreader_autoscroll&hl=en&gl=US
I want to make as like this. Can anyone help please.
Also tried with this. But it shows blank page after some scrolls.
#Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_DOWN) {
pdfView.scrollTo(0, pdfView.getScrollY() -24);
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_DOWN) {
pdfView.scrollTo(0, pdfView.getScrollY() + 24);
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}
You can simply use this PDF viewer from github.
It's based on the same 'barsteksc' pdf viewer with the feature to jump to any pages.
It's MagicalPdfViewer and you can use 'jumpTo(pageNo)' method to simply jump to the specific page. It also gives you the option to animate to the specific page with the same method, just pass 'true' as the 2nd parameter.
Moreover, if you pass the values like '-1' and 'bigger than pageNo', It will automatically scroll to the 0 & last page respectively.
Give it a try & let me know if you got what you wanted.
I have a WebView and I am loading the data from the backend.The data is very long paragraph and it is in Html format.It is working.I have to implement change font size settings to my application.When radio button named "small" clicks,text should appear in small font,when "large" clicks text should appear in large font.The content dispaly is done in ChapterDetailFragment.class.The dialg which shows the "change font option" is in Menu in actionbar and in drawer.
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.font_change) {
dialog = new Dialog(HomeActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.font_change_dialog);
dialog.show();
dialog.setCanceledOnTouchOutside(true);
//here i have to write the code for clicks of radiobutton "small","large"
}
}
This is the line for loading paragraph to the array adapter
ParagraphAdapter.class
mViewHolder.mChapterContextTextView.loadData(getItem(position - 1).getContent(), "text/html; charset=UTF-8;", null);
I don't know how to implement this.Please anyone help me
in onClick of "large" radio button, save value LARGE for large.Similarly in onClick of small radio button(value SMALL for small )
public void onTextLarge(View view) {
if (fragment.getClass().getSimpleName().equalsIgnoreCase("HomeFragment")){
setSharedPreference("FONT","LARGE");
fragment = new HomeFragment();
dialog.dismiss();
}
In the adapter,
if (fontsize.equals("LARGE")) {
mViewHolder.settings = mViewHolder.mChapterContextTextView.getSettings();
mViewHolder.settings.setTextZoom(mViewHolder.settings.getTextZoom() + 30);
mViewHolder.mChapterContextTextView.loadData(getItem(position - 1).getContent(),
"text/html; charset=UTF-8;", null);
Similarly done for fontsize.equals("SMALL"). :)
I have this very basic code which will be used to display tabs only when CheckMenuItem is selected:
CheckMenuItem toolbarSubMenuNavigation = new CheckMenuItem("Navigation");
toolbarSubMenuNavigation.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
// Show or hide tabs
System.out.println("subsystem1 #1 Enabled!");
}
});
This is the code that I want to show or hide when the check box is selected:
TabPane tabPane = new TabPane();
Tab tab0 = new Tab("blue");
tab.setContent(new Rectangle(200,200, Color.BLUE));
Tab tab1 = new Tab("green");
tab.setContent(new Rectangle(200,200, Color.GREEN));
tabPane.getTabs().addAll(tab0, tab1);
Can you tell me how I can show the tabs only when the CheckMenuItem is true? And I want to do this dynamically.
Something like that can work
CheckMenuItem item = new CheckMenuItem();
Tab t = new Tab();
t.getGraphic().visibleProperty().bind(item.selectedProperty());
The item.selectedProperty() is true when is check, and false when it's not, so if you bind it to the visibleProperty() of your node it will visible when item is checked, and not visible when it's not checked
In my application I have a main page with a menustrip to navigate to other forms Since i want it to be opened always I set it as a MDICONTAINER .now I need to open a form on menustripclick event as child i set the form like this
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
this.IsMdiContainer = true;
loginmain();
intialsetupform();
}
private void companyToolStripMenuItem_Click(object sender, EventArgs e)
{
Master.CompanyMasterForm cmpnymasterform = new Master.CompanyMasterForm();
cmpnymasterform.MdiParent= this ;
cmpnymasterform.Show();
}}
All was Ok and I got the childwindows work correctly
but Now i need to add two panels in the mainform << one for showing status meddages and other for showing some other controls
I had added the panel and anchored them and the issue is that now when the child window opens all the panels and controls of the parentform(mainform) comes above the childwindow controls which make it unreadable Please provide any ideas to overcome this
I had set the location of all the pannels using Anchor properties of the control now the controls know there location
and set the message box to bottom using dock property
I created a class from Dialog which contains a TextArea :
public class Alert extends Dialog {
private Container c = new Container(new BorderLayout());
private Label titre = new Label("Mobile Banking");
private TextArea chp;
private Command[] comms;
public Alert(String text, Command[] comms)
{
super();
titre.setUIID("titre_alert");
titre.setAlignment(Label.CENTER);
this.comms = comms;
setAutoDispose(true);
for (int cmd=0; cmd<comms.length; cmd++)
addCommand(comms[cmd]);
chp = new TextArea();
chp.setEditable(false);
chp.setAlignment(Label.CENTER);
chp.getSelectedStyle().setBorder(null);
chp.getUnselectedStyle().setBorder(null);
chp.getSelectedStyle().setBgColor(this.getStyle().getBgColor());
chp.getUnselectedStyle().setBgColor(this.getStyle().getBgColor());
if (text.length() % 2 != 0)
text = " ".concat(text);
while (text.substring(0, (text.length()/2)+1).length() < chp.getMaxSize()/2)
{
text = " ".concat(text);
}
chp.setText(text);
c.addComponent(BorderLayout.NORTH, titre);
c.addComponent(BorderLayout.CENTER, chp);
}
public Command affiche()
{
return show(null, c, comms);
}
}
Inside a Form I start a thread which makes a HttpConnection call and other tasks. If the tasks end successfully then I call the affiche() method of the above class Alert :
alert = new Alert("Chargement effectué avec succès !", new Command[]{ok});
cntnr.removeComponent(cPatienter); // container displaying the "please wait..."
repaint(); // repainting the Form
if (alert.affiche() == ok) // showing the confirmation of successfullness of the task
{
alert.dispose();
controller.displayScreen("Menuprincipale");
}
The problem is that , sometimes , the text shown when calling the affiche() method is duplicated : it should show only the text Chargement effectué avec succès ! but sometimes it shows the text and also Chargement effectué.
So how to make it that only the text parameter is only shown but not duplicated ?
You are invoking LWUIT on a separate thread which is illegal. You need to use Display.callSerially to avoid a race condition in the text layout code. Something like this:
Display.getInstance().callSerially(new Runnable() {
public void run() {
// your LWUIT code here, no need for repaints
}
});
A better approach is to use LWUIT4IO for your networking since it does this seamlessly for you.